GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

d3_dispatch.on   B
last analyzed

Complexity

Conditions 8
Paths 10

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
cc 8
nc 10
nop 2
rs 7.7777
1
!function() {
2
  var d3 = {
3
    version: "3.5.5"
4
  };
5
  var d3_arraySlice = [].slice, d3_array = function(list) {
6
    return d3_arraySlice.call(list);
7
  };
8
  var d3_document = this.document;
9
  function d3_documentElement(node) {
10
    return node && (node.ownerDocument || node.document || node).documentElement;
11
  }
12
  function d3_window(node) {
13
    return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
14
  }
15
  if (d3_document) {
16
    try {
17
      d3_array(d3_document.documentElement.childNodes)[0].nodeType;
0 ignored issues
show
introduced by
The result of the property access to d3_array(d3_document.doc....childNodes).0.nodeType is not used.
Loading history...
18
    } catch (e) {
19
      d3_array = function(list) {
20
        var i = list.length, array = new Array(i);
21
        while (i--) array[i] = list[i];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
22
        return array;
23
      };
24
    }
25
  }
26
  if (!Date.now) Date.now = function() {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Compatibility Best Practice introduced by
You are extending the built-in type Date. This may have unintended consequences on other objects using this built-in type. Consider subclassing instead.
Loading history...
27
    return +new Date();
28
  };
29
  if (d3_document) {
30
    try {
31
      d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
32
    } catch (error) {
33
      var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
34
      d3_element_prototype.setAttribute = function(name, value) {
35
        d3_element_setAttribute.call(this, name, value + "");
36
      };
37
      d3_element_prototype.setAttributeNS = function(space, local, value) {
38
        d3_element_setAttributeNS.call(this, space, local, value + "");
39
      };
40
      d3_style_prototype.setProperty = function(name, value, priority) {
41
        d3_style_setProperty.call(this, name, value + "", priority);
42
      };
43
    }
44
  }
45
  d3.ascending = d3_ascending;
46
  function d3_ascending(a, b) {
47
    return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
48
  }
49
  d3.descending = function(a, b) {
50
    return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
51
  };
52 View Code Duplication
  d3.min = function(array, f) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
53
    var i = -1, n = array.length, a, b;
54
    if (arguments.length === 1) {
55
      while (++i < n) if ((b = array[i]) != null && b >= b) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
56
        a = b;
57
        break;
58
      }
59
      while (++i < n) if ((b = array[i]) != null && a > b) a = b;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable a seems to not be initialized for all possible execution paths.
Loading history...
60
    } else {
61
      while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
62
        a = b;
63
        break;
64
      }
65
      while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
66
    }
67
    return a;
68
  };
69 View Code Duplication
  d3.max = function(array, f) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
70
    var i = -1, n = array.length, a, b;
71
    if (arguments.length === 1) {
72
      while (++i < n) if ((b = array[i]) != null && b >= b) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
73
        a = b;
74
        break;
75
      }
76
      while (++i < n) if ((b = array[i]) != null && b > a) a = b;
0 ignored issues
show
Bug introduced by
The variable a seems to not be initialized for all possible execution paths.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
77
    } else {
78
      while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
79
        a = b;
80
        break;
81
      }
82
      while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
83
    }
84
    return a;
85
  };
86 View Code Duplication
  d3.extent = function(array, f) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
87
    var i = -1, n = array.length, a, b, c;
88
    if (arguments.length === 1) {
89
      while (++i < n) if ((b = array[i]) != null && b >= b) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
90
        a = c = b;
91
        break;
92
      }
93
      while (++i < n) if ((b = array[i]) != null) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
94
        if (a > b) a = b;
0 ignored issues
show
Bug introduced by
The variable a seems to not be initialized for all possible execution paths.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
95
        if (c < b) c = b;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable c seems to not be initialized for all possible execution paths.
Loading history...
96
      }
97
    } else {
98
      while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
99
        a = c = b;
100
        break;
101
      }
102
      while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
103
        if (a > b) a = b;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
104
        if (c < b) c = b;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
105
      }
106
    }
107
    return [ a, c ];
108
  };
109
  function d3_number(x) {
110
    return x === null ? NaN : +x;
111
  }
112
  function d3_numeric(x) {
113
    return !isNaN(x);
114
  }
115
  d3.sum = function(array, f) {
116
    var s = 0, n = array.length, a, i = -1;
117
    if (arguments.length === 1) {
118
      while (++i < n) if (d3_numeric(a = +array[i])) s += a;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
119
    } else {
120
      while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
121
    }
122
    return s;
123
  };
124
  d3.mean = function(array, f) {
125
    var s = 0, n = array.length, a, i = -1, j = n;
126
    if (arguments.length === 1) {
127
      while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
128
    } else {
129
      while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
130
    }
131
    if (j) return s / j;
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if j is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
132
  };
133
  d3.quantile = function(values, p) {
134
    var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
135
    return e ? v + e * (values[h] - v) : v;
136
  };
137
  d3.median = function(array, f) {
138
    var numbers = [], n = array.length, a, i = -1;
139
    if (arguments.length === 1) {
140
      while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
141
    } else {
142
      while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
143
    }
144
    if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity Best Practice introduced by
There is no return statement if numbers.length is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
145
  };
146
  d3.variance = function(array, f) {
147
    var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
148
    if (arguments.length === 1) {
149
      while (++i < n) {
150
        if (d3_numeric(a = d3_number(array[i]))) {
151
          d = a - m;
152
          m += d / ++j;
153
          s += d * (a - m);
154
        }
155
      }
156
    } else {
157
      while (++i < n) {
158
        if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
159
          d = a - m;
160
          m += d / ++j;
161
          s += d * (a - m);
162
        }
163
      }
164
    }
165
    if (j > 1) return s / (j - 1);
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if j > 1 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
166
  };
167
  d3.deviation = function() {
168
    var v = d3.variance.apply(this, arguments);
169
    return v ? Math.sqrt(v) : v;
170
  };
171
  function d3_bisector(compare) {
172
    return {
173
      left: function(a, x, lo, hi) {
174
        if (arguments.length < 3) lo = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
175
        if (arguments.length < 4) hi = a.length;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
176
        while (lo < hi) {
177
          var mid = lo + hi >>> 1;
178
          if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
179
        }
180
        return lo;
181
      },
182
      right: function(a, x, lo, hi) {
183
        if (arguments.length < 3) lo = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
184
        if (arguments.length < 4) hi = a.length;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
185
        while (lo < hi) {
186
          var mid = lo + hi >>> 1;
187
          if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
188
        }
189
        return lo;
190
      }
191
    };
192
  }
193
  var d3_bisect = d3_bisector(d3_ascending);
194
  d3.bisectLeft = d3_bisect.left;
195
  d3.bisect = d3.bisectRight = d3_bisect.right;
196
  d3.bisector = function(f) {
197
    return d3_bisector(f.length === 1 ? function(d, x) {
198
      return d3_ascending(f(d), x);
199
    } : f);
200
  };
201
  d3.shuffle = function(array, i0, i1) {
202
    if ((m = arguments.length) < 3) {
203
      i1 = array.length;
204
      if (m < 2) i0 = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
205
    }
206
    var m = i1 - i0, t, i;
207
    while (m) {
208
      i = Math.random() * m-- | 0;
209
      t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
210
    }
211
    return array;
212
  };
213
  d3.permute = function(array, indexes) {
214
    var i = indexes.length, permutes = new Array(i);
215
    while (i--) permutes[i] = array[indexes[i]];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
216
    return permutes;
217
  };
218
  d3.pairs = function(array) {
219
    var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
220
    while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
0 ignored issues
show
Unused Code introduced by
The variable p0 seems to be never used. Consider removing it.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
221
    return pairs;
222
  };
223
  d3.zip = function() {
224
    if (!(n = arguments.length)) return [];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
225
    for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
226
      for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
227
        zip[j] = arguments[j][i];
228
      }
229
    }
230
    return zips;
231
  };
232
  function d3_zipLength(d) {
233
    return d.length;
234
  }
235
  d3.transpose = function(matrix) {
236
    return d3.zip.apply(d3, matrix);
237
  };
238
  d3.keys = function(map) {
239
    var keys = [];
240
    for (var key in map) keys.push(key);
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
241
    return keys;
242
  };
243
  d3.values = function(map) {
244
    var values = [];
245
    for (var key in map) values.push(map[key]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
246
    return values;
247
  };
248
  d3.entries = function(map) {
249
    var entries = [];
250
    for (var key in map) entries.push({
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
251
      key: key,
252
      value: map[key]
253
    });
254
    return entries;
255
  };
256
  d3.merge = function(arrays) {
257
    var n = arrays.length, m, i = -1, j = 0, merged, array;
258
    while (++i < n) j += arrays[i].length;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
259
    merged = new Array(j);
260
    while (--n >= 0) {
261
      array = arrays[n];
262
      m = array.length;
263
      while (--m >= 0) {
264
        merged[--j] = array[m];
265
      }
266
    }
267
    return merged;
268
  };
269
  var abs = Math.abs;
270
  d3.range = function(start, stop, step) {
271
    if (arguments.length < 3) {
272
      step = 1;
273
      if (arguments.length < 2) {
274
        stop = start;
275
        start = 0;
276
      }
277
    }
278
    if ((stop - start) / step === Infinity) throw new Error("infinite range");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
279
    var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
280
    start *= k, stop *= k, step *= k;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
281
    if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
282
    return range;
283
  };
284
  function d3_range_integerScale(x) {
285
    var k = 1;
286
    while (x * k % 1) k *= 10;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
287
    return k;
288
  }
289
  function d3_class(ctor, properties) {
290
    for (var key in properties) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
291
      Object.defineProperty(ctor.prototype, key, {
292
        value: properties[key],
293
        enumerable: false
294
      });
295
    }
296
  }
297
  d3.map = function(object, f) {
298
    var map = new d3_Map();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_Map should be capitalized.
Loading history...
299
    if (object instanceof d3_Map) {
300
      object.forEach(function(key, value) {
301
        map.set(key, value);
302
      });
303
    } else if (Array.isArray(object)) {
304
      var i = -1, n = object.length, o;
305
      if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
306
    } else {
307
      for (var key in object) map.set(key, object[key]);
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
308
    }
309
    return map;
310
  };
311
  function d3_Map() {
312
    this._ = Object.create(null);
313
  }
314
  var d3_map_proto = "__proto__", d3_map_zero = "\x00";
315
  d3_class(d3_Map, {
316
    has: d3_map_has,
317
    get: function(key) {
318
      return this._[d3_map_escape(key)];
319
    },
320
    set: function(key, value) {
321
      return this._[d3_map_escape(key)] = value;
322
    },
323
    remove: d3_map_remove,
324
    keys: d3_map_keys,
325
    values: function() {
326
      var values = [];
327
      for (var key in this._) values.push(this._[key]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
328
      return values;
329
    },
330
    entries: function() {
331
      var entries = [];
332
      for (var key in this._) entries.push({
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
333
        key: d3_map_unescape(key),
334
        value: this._[key]
335
      });
336
      return entries;
337
    },
338
    size: d3_map_size,
339
    empty: d3_map_empty,
340
    forEach: function(f) {
341
      for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
342
    }
343
  });
344
  function d3_map_escape(key) {
345
    return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
346
  }
347
  function d3_map_unescape(key) {
348
    return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
349
  }
350
  function d3_map_has(key) {
351
    return d3_map_escape(key) in this._;
352
  }
353
  function d3_map_remove(key) {
354
    return (key = d3_map_escape(key)) in this._ && delete this._[key];
355
  }
356
  function d3_map_keys() {
357
    var keys = [];
358
    for (var key in this._) keys.push(d3_map_unescape(key));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
359
    return keys;
360
  }
361
  function d3_map_size() {
362
    var size = 0;
363
    for (var key in this._) ++size;
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
364
    return size;
365
  }
366
  function d3_map_empty() {
367
    for (var key in this._) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
368
    return true;
369
  }
370
  d3.nest = function() {
371
    var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
372
    function map(mapType, array, depth) {
373
      if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
374
      var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_Map should be capitalized.
Loading history...
375
      while (++i < n) {
376
        if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
377
          values.push(object);
378
        } else {
379
          valuesByKey.set(keyValue, [ object ]);
380
        }
381
      }
382
      if (mapType) {
383
        object = mapType();
384
        setter = function(keyValue, values) {
385
          object.set(keyValue, map(mapType, values, depth));
386
        };
387
      } else {
388
        object = {};
389
        setter = function(keyValue, values) {
390
          object[keyValue] = map(mapType, values, depth);
391
        };
392
      }
393
      valuesByKey.forEach(setter);
394
      return object;
395
    }
396
    function entries(map, depth) {
397
      if (depth >= keys.length) return map;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
398
      var array = [], sortKey = sortKeys[depth++];
399
      map.forEach(function(key, keyMap) {
400
        array.push({
401
          key: key,
402
          values: entries(keyMap, depth)
403
        });
404
      });
405
      return sortKey ? array.sort(function(a, b) {
406
        return sortKey(a.key, b.key);
407
      }) : array;
408
    }
409
    nest.map = function(array, mapType) {
410
      return map(mapType, array, 0);
411
    };
412
    nest.entries = function(array) {
413
      return entries(map(d3.map, array, 0), 0);
414
    };
415
    nest.key = function(d) {
416
      keys.push(d);
417
      return nest;
418
    };
419
    nest.sortKeys = function(order) {
420
      sortKeys[keys.length - 1] = order;
421
      return nest;
422
    };
423
    nest.sortValues = function(order) {
424
      sortValues = order;
425
      return nest;
426
    };
427
    nest.rollup = function(f) {
428
      rollup = f;
429
      return nest;
430
    };
431
    return nest;
432
  };
433
  d3.set = function(array) {
434
    var set = new d3_Set();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_Set should be capitalized.
Loading history...
435
    if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
436
    return set;
437
  };
438
  function d3_Set() {
439
    this._ = Object.create(null);
440
  }
441
  d3_class(d3_Set, {
442
    has: d3_map_has,
443
    add: function(key) {
444
      this._[d3_map_escape(key += "")] = true;
445
      return key;
446
    },
447
    remove: d3_map_remove,
448
    values: d3_map_keys,
449
    size: d3_map_size,
450
    empty: d3_map_empty,
451
    forEach: function(f) {
452
      for (var key in this._) f.call(this, d3_map_unescape(key));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
453
    }
454
  });
455
  d3.behavior = {};
456
  function d3_identity(d) {
457
    return d;
458
  }
459
  d3.rebind = function(target, source) {
460
    var i = 1, n = arguments.length, method;
461
    while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable method seems to not be initialized for all possible execution paths.
Loading history...
462
    return target;
463
  };
464
  function d3_rebind(target, source, method) {
465
    return function() {
466
      var value = method.apply(source, arguments);
467
      return value === source ? target : value;
468
    };
469
  }
470
  function d3_vendorSymbol(object, name) {
471
    if (name in object) return name;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
472
    name = name.charAt(0).toUpperCase() + name.slice(1);
473
    for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
474
      var prefixName = d3_vendorPrefixes[i] + name;
475
      if (prefixName in object) return prefixName;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
476
    }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
477
  }
478
  var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
479
  function d3_noop() {}
480
  d3.dispatch = function() {
481
    var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_dispatch should be capitalized.
Loading history...
482
    while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
483
    return dispatch;
484
  };
485
  function d3_dispatch() {}
486
  d3_dispatch.prototype.on = function(type, listener) {
487
    var i = type.indexOf("."), name = "";
488
    if (i >= 0) {
489
      name = type.slice(i + 1);
490
      type = type.slice(0, i);
491
    }
492
    if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
493
    if (arguments.length === 2) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if arguments.length === 2 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
494
      if (listener == null) for (type in this) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
495
        if (this.hasOwnProperty(type)) this[type].on(name, null);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
496
      }
497
      return this;
498
    }
499
  };
500
  function d3_dispatch_event(dispatch) {
501
    var listeners = [], listenerByName = new d3_Map();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_Map should be capitalized.
Loading history...
502
    function event() {
503
      var z = listeners, i = -1, n = z.length, l;
504
      while (++i < n) if (l = z[i].on) l.apply(this, arguments);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
505
      return dispatch;
506
    }
507
    event.on = function(name, listener) {
508
      var l = listenerByName.get(name), i;
509
      if (arguments.length < 2) return l && l.on;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
510
      if (l) {
511
        l.on = null;
512
        listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
513
        listenerByName.remove(name);
514
      }
515
      if (listener) listeners.push(listenerByName.set(name, {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
516
        on: listener
517
      }));
518
      return dispatch;
519
    };
520
    return event;
521
  }
522
  d3.event = null;
523
  function d3_eventPreventDefault() {
524
    d3.event.preventDefault();
525
  }
526
  function d3_eventSource() {
527
    var e = d3.event, s;
528
    while (s = e.sourceEvent) e = s;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
529
    return e;
530
  }
531
  function d3_eventDispatch(target) {
532
    var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_dispatch should be capitalized.
Loading history...
533
    while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
534
    dispatch.of = function(thiz, argumentz) {
535
      return function(e1) {
536
        try {
537
          var e0 = e1.sourceEvent = d3.event;
538
          e1.target = target;
539
          d3.event = e1;
540
          dispatch[e1.type].apply(thiz, argumentz);
541
        } finally {
542
          d3.event = e0;
543
        }
544
      };
545
    };
546
    return dispatch;
547
  }
548
  d3.requote = function(s) {
549
    return s.replace(d3_requote_re, "\\$&");
550
  };
551
  var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
552
  var d3_subclass = {}.__proto__ ? function(object, prototype) {
553
    object.__proto__ = prototype;
554
  } : function(object, prototype) {
555
    for (var property in prototype) object[property] = prototype[property];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
556
  };
557
  function d3_selection(groups) {
558
    d3_subclass(groups, d3_selectionPrototype);
559
    return groups;
560
  }
561
  var d3_select = function(s, n) {
562
    return n.querySelector(s);
563
  }, d3_selectAll = function(s, n) {
564
    return n.querySelectorAll(s);
565
  }, d3_selectMatches = function(n, s) {
566
    var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
567
    d3_selectMatches = function(n, s) {
568
      return d3_selectMatcher.call(n, s);
569
    };
570
    return d3_selectMatches(n, s);
571
  };
572
  if (typeof Sizzle === "function") {
0 ignored issues
show
Bug introduced by
The variable Sizzle seems to be never declared. If this is a global, consider adding a /** global: Sizzle */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
573
    d3_select = function(s, n) {
574
      return Sizzle(s, n)[0] || null;
575
    };
576
    d3_selectAll = Sizzle;
0 ignored issues
show
Bug introduced by
The variable Sizzle seems to be never declared. If this is a global, consider adding a /** global: Sizzle */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
577
    d3_selectMatches = Sizzle.matchesSelector;
578
  }
579
  d3.selection = function() {
580
    return d3.select(d3_document.documentElement);
581
  };
582
  var d3_selectionPrototype = d3.selection.prototype = [];
583
  d3_selectionPrototype.select = function(selector) {
584
    var subgroups = [], subgroup, subnode, group, node;
585
    selector = d3_selection_selector(selector);
586
    for (var j = -1, m = this.length; ++j < m; ) {
587
      subgroups.push(subgroup = []);
588
      subgroup.parentNode = (group = this[j]).parentNode;
589
      for (var i = -1, n = group.length; ++i < n; ) {
590
        if (node = group[i]) {
591
          subgroup.push(subnode = selector.call(node, node.__data__, i, j));
592
          if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
593
        } else {
594
          subgroup.push(null);
595
        }
596
      }
597
    }
598
    return d3_selection(subgroups);
599
  };
600
  function d3_selection_selector(selector) {
601
    return typeof selector === "function" ? selector : function() {
602
      return d3_select(selector, this);
603
    };
604
  }
605
  d3_selectionPrototype.selectAll = function(selector) {
606
    var subgroups = [], subgroup, node;
607
    selector = d3_selection_selectorAll(selector);
608
    for (var j = -1, m = this.length; ++j < m; ) {
609
      for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
610
        if (node = group[i]) {
611
          subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
612
          subgroup.parentNode = node;
613
        }
614
      }
615
    }
616
    return d3_selection(subgroups);
617
  };
618
  function d3_selection_selectorAll(selector) {
619
    return typeof selector === "function" ? selector : function() {
620
      return d3_selectAll(selector, this);
621
    };
622
  }
623
  var d3_nsPrefix = {
624
    svg: "http://www.w3.org/2000/svg",
625
    xhtml: "http://www.w3.org/1999/xhtml",
626
    xlink: "http://www.w3.org/1999/xlink",
627
    xml: "http://www.w3.org/XML/1998/namespace",
628
    xmlns: "http://www.w3.org/2000/xmlns/"
629
  };
630
  d3.ns = {
631
    prefix: d3_nsPrefix,
632
    qualify: function(name) {
633
      var i = name.indexOf(":"), prefix = name;
634
      if (i >= 0) {
635
        prefix = name.slice(0, i);
636
        name = name.slice(i + 1);
637
      }
638
      return d3_nsPrefix.hasOwnProperty(prefix) ? {
639
        space: d3_nsPrefix[prefix],
640
        local: name
641
      } : name;
642
    }
643
  };
644
  d3_selectionPrototype.attr = function(name, value) {
645
    if (arguments.length < 2) {
646
      if (typeof name === "string") {
647
        var node = this.node();
648
        name = d3.ns.qualify(name);
649
        return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
650
      }
651
      for (value in name) this.each(d3_selection_attr(value, name[value]));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
652
      return this;
653
    }
654
    return this.each(d3_selection_attr(name, value));
655
  };
656
  function d3_selection_attr(name, value) {
657
    name = d3.ns.qualify(name);
658
    function attrNull() {
659
      this.removeAttribute(name);
660
    }
661
    function attrNullNS() {
662
      this.removeAttributeNS(name.space, name.local);
663
    }
664
    function attrConstant() {
665
      this.setAttribute(name, value);
666
    }
667
    function attrConstantNS() {
668
      this.setAttributeNS(name.space, name.local, value);
669
    }
670
    function attrFunction() {
671
      var x = value.apply(this, arguments);
672
      if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
673
    }
674
    function attrFunctionNS() {
675
      var x = value.apply(this, arguments);
676
      if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
677
    }
678
    return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
679
  }
680
  function d3_collapse(s) {
681
    return s.trim().replace(/\s+/g, " ");
682
  }
683
  d3_selectionPrototype.classed = function(name, value) {
684
    if (arguments.length < 2) {
685
      if (typeof name === "string") {
686
        var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
687
        if (value = node.classList) {
688
          while (++i < n) if (!value.contains(name[i])) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
689
        } else {
690
          value = node.getAttribute("class");
691
          while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
692
        }
693
        return true;
694
      }
695
      for (value in name) this.each(d3_selection_classed(value, name[value]));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
696
      return this;
697
    }
698
    return this.each(d3_selection_classed(name, value));
699
  };
700
  function d3_selection_classedRe(name) {
701
    return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
702
  }
703
  function d3_selection_classes(name) {
704
    return (name + "").trim().split(/^|\s+/);
705
  }
706
  function d3_selection_classed(name, value) {
707
    name = d3_selection_classes(name).map(d3_selection_classedName);
708
    var n = name.length;
709
    function classedConstant() {
710
      var i = -1;
711
      while (++i < n) name[i](this, value);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
712
    }
713
    function classedFunction() {
714
      var i = -1, x = value.apply(this, arguments);
715
      while (++i < n) name[i](this, x);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
716
    }
717
    return typeof value === "function" ? classedFunction : classedConstant;
718
  }
719
  function d3_selection_classedName(name) {
720
    var re = d3_selection_classedRe(name);
721
    return function(node, value) {
722
      if (c = node.classList) return value ? c.add(name) : c.remove(name);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
723
      var c = node.getAttribute("class") || "";
724
      if (value) {
725
        re.lastIndex = 0;
726
        if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity Best Practice introduced by
There is no return statement if !re.test(c) is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
727
      } else {
728
        node.setAttribute("class", d3_collapse(c.replace(re, " ")));
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
729
      }
730
    };
731
  }
732
  d3_selectionPrototype.style = function(name, value, priority) {
733
    var n = arguments.length;
734
    if (n < 3) {
735
      if (typeof name !== "string") {
736
        if (n < 2) value = "";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
737
        for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
738
        return this;
739
      }
740
      if (n < 2) {
741
        var node = this.node();
742
        return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
743
      }
744
      priority = "";
745
    }
746
    return this.each(d3_selection_style(name, value, priority));
747
  };
748
  function d3_selection_style(name, value, priority) {
749
    function styleNull() {
750
      this.style.removeProperty(name);
751
    }
752
    function styleConstant() {
753
      this.style.setProperty(name, value, priority);
754
    }
755
    function styleFunction() {
756
      var x = value.apply(this, arguments);
757
      if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
758
    }
759
    return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
760
  }
761
  d3_selectionPrototype.property = function(name, value) {
762
    if (arguments.length < 2) {
763
      if (typeof name === "string") return this.node()[name];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
764
      for (value in name) this.each(d3_selection_property(value, name[value]));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
765
      return this;
766
    }
767
    return this.each(d3_selection_property(name, value));
768
  };
769
  function d3_selection_property(name, value) {
770
    function propertyNull() {
771
      delete this[name];
772
    }
773
    function propertyConstant() {
774
      this[name] = value;
775
    }
776
    function propertyFunction() {
777
      var x = value.apply(this, arguments);
778
      if (x == null) delete this[name]; else this[name] = x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
779
    }
780
    return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
781
  }
782
  d3_selectionPrototype.text = function(value) {
783
    return arguments.length ? this.each(typeof value === "function" ? function() {
784
      var v = value.apply(this, arguments);
785
      this.textContent = v == null ? "" : v;
786
    } : value == null ? function() {
787
      this.textContent = "";
788
    } : function() {
789
      this.textContent = value;
790
    }) : this.node().textContent;
791
  };
792
  d3_selectionPrototype.html = function(value) {
793
    return arguments.length ? this.each(typeof value === "function" ? function() {
794
      var v = value.apply(this, arguments);
795
      this.innerHTML = v == null ? "" : v;
796
    } : value == null ? function() {
797
      this.innerHTML = "";
798
    } : function() {
799
      this.innerHTML = value;
800
    }) : this.node().innerHTML;
801
  };
802
  d3_selectionPrototype.append = function(name) {
803
    name = d3_selection_creator(name);
804
    return this.select(function() {
805
      return this.appendChild(name.apply(this, arguments));
806
    });
807
  };
808
  function d3_selection_creator(name) {
809
    function create() {
810
      var document = this.ownerDocument, namespace = this.namespaceURI;
811
      return namespace ? document.createElementNS(namespace, name) : document.createElement(name);
812
    }
813
    function createNS() {
814
      return this.ownerDocument.createElementNS(name.space, name.local);
815
    }
816
    return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
817
  }
818
  d3_selectionPrototype.insert = function(name, before) {
819
    name = d3_selection_creator(name);
820
    before = d3_selection_selector(before);
821
    return this.select(function() {
822
      return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
823
    });
824
  };
825
  d3_selectionPrototype.remove = function() {
826
    return this.each(d3_selectionRemove);
827
  };
828
  function d3_selectionRemove() {
829
    var parent = this.parentNode;
830
    if (parent) parent.removeChild(this);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
831
  }
832
  d3_selectionPrototype.data = function(value, key) {
833
    var i = -1, n = this.length, group, node;
834
    if (!arguments.length) {
835
      value = new Array(n = (group = this[0]).length);
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
836
      while (++i < n) {
837
        if (node = group[i]) {
838
          value[i] = node.__data__;
839
        }
840
      }
841
      return value;
842
    }
843
    function bind(group, groupData) {
844
      var i, n = group.length, m = groupData.length, n0 = Math.min(n, m), updateNodes = new Array(m), enterNodes = new Array(m), exitNodes = new Array(n), node, nodeData;
845
      if (key) {
846
        var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_Map should be capitalized.
Loading history...
847
        for (i = -1; ++i < n; ) {
848
          if (nodeByKeyValue.has(keyValue = key.call(node = group[i], node.__data__, i))) {
849
            exitNodes[i] = node;
850
          } else {
851
            nodeByKeyValue.set(keyValue, node);
852
          }
853
          keyValues[i] = keyValue;
854
        }
855
        for (i = -1; ++i < m; ) {
856
          if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
857
            enterNodes[i] = d3_selection_dataNode(nodeData);
858
          } else if (node !== true) {
859
            updateNodes[i] = node;
860
            node.__data__ = nodeData;
861
          }
862
          nodeByKeyValue.set(keyValue, true);
863
        }
864
        for (i = -1; ++i < n; ) {
865
          if (nodeByKeyValue.get(keyValues[i]) !== true) {
866
            exitNodes[i] = group[i];
867
          }
868
        }
869
      } else {
870
        for (i = -1; ++i < n0; ) {
871
          node = group[i];
872
          nodeData = groupData[i];
873
          if (node) {
874
            node.__data__ = nodeData;
875
            updateNodes[i] = node;
876
          } else {
877
            enterNodes[i] = d3_selection_dataNode(nodeData);
878
          }
879
        }
880
        for (;i < m; ++i) {
881
          enterNodes[i] = d3_selection_dataNode(groupData[i]);
882
        }
883
        for (;i < n; ++i) {
884
          exitNodes[i] = group[i];
885
        }
886
      }
887
      enterNodes.update = updateNodes;
888
      enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
889
      enter.push(enterNodes);
890
      update.push(updateNodes);
891
      exit.push(exitNodes);
892
    }
893
    var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
894
    if (typeof value === "function") {
895
      while (++i < n) {
896
        bind(group = this[i], value.call(group, group.parentNode.__data__, i));
897
      }
898
    } else {
899
      while (++i < n) {
900
        bind(group = this[i], value);
0 ignored issues
show
Unused Code introduced by
The assignment to variable group seems to be never used. Consider removing it.
Loading history...
901
      }
902
    }
903
    update.enter = function() {
904
      return enter;
905
    };
906
    update.exit = function() {
907
      return exit;
908
    };
909
    return update;
910
  };
911
  function d3_selection_dataNode(data) {
912
    return {
913
      __data__: data
914
    };
915
  }
916
  d3_selectionPrototype.datum = function(value) {
917
    return arguments.length ? this.property("__data__", value) : this.property("__data__");
918
  };
919
  d3_selectionPrototype.filter = function(filter) {
920
    var subgroups = [], subgroup, group, node;
921
    if (typeof filter !== "function") filter = d3_selection_filter(filter);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
922
    for (var j = 0, m = this.length; j < m; j++) {
923
      subgroups.push(subgroup = []);
924
      subgroup.parentNode = (group = this[j]).parentNode;
925
      for (var i = 0, n = group.length; i < n; i++) {
926
        if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
927
          subgroup.push(node);
928
        }
929
      }
930
    }
931
    return d3_selection(subgroups);
932
  };
933
  function d3_selection_filter(selector) {
934
    return function() {
935
      return d3_selectMatches(this, selector);
936
    };
937
  }
938
  d3_selectionPrototype.order = function() {
939
    for (var j = -1, m = this.length; ++j < m; ) {
940
      for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
941
        if (node = group[i]) {
942
          if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
943
          next = node;
944
        }
945
      }
946
    }
947
    return this;
948
  };
949
  d3_selectionPrototype.sort = function(comparator) {
950
    comparator = d3_selection_sortComparator.apply(this, arguments);
951
    for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
952
    return this.order();
953
  };
954
  function d3_selection_sortComparator(comparator) {
955
    if (!arguments.length) comparator = d3_ascending;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
956
    return function(a, b) {
957
      return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
958
    };
959
  }
960
  d3_selectionPrototype.each = function(callback) {
961
    return d3_selection_each(this, function(node, i, j) {
962
      callback.call(node, node.__data__, i, j);
963
    });
964
  };
965
  function d3_selection_each(groups, callback) {
966
    for (var j = 0, m = groups.length; j < m; j++) {
967
      for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
968
        if (node = group[i]) callback(node, i, j);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
969
      }
970
    }
971
    return groups;
972
  }
973
  d3_selectionPrototype.call = function(callback) {
974
    var args = d3_array(arguments);
975
    callback.apply(args[0] = this, args);
976
    return this;
977
  };
978
  d3_selectionPrototype.empty = function() {
979
    return !this.node();
980
  };
981
  d3_selectionPrototype.node = function() {
982
    for (var j = 0, m = this.length; j < m; j++) {
983
      for (var group = this[j], i = 0, n = group.length; i < n; i++) {
984
        var node = group[i];
985
        if (node) return node;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
986
      }
987
    }
988
    return null;
989
  };
990
  d3_selectionPrototype.size = function() {
991
    var n = 0;
992
    d3_selection_each(this, function() {
993
      ++n;
994
    });
995
    return n;
996
  };
997
  function d3_selection_enter(selection) {
998
    d3_subclass(selection, d3_selection_enterPrototype);
999
    return selection;
1000
  }
1001
  var d3_selection_enterPrototype = [];
1002
  d3.selection.enter = d3_selection_enter;
1003
  d3.selection.enter.prototype = d3_selection_enterPrototype;
1004
  d3_selection_enterPrototype.append = d3_selectionPrototype.append;
1005
  d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
1006
  d3_selection_enterPrototype.node = d3_selectionPrototype.node;
1007
  d3_selection_enterPrototype.call = d3_selectionPrototype.call;
1008
  d3_selection_enterPrototype.size = d3_selectionPrototype.size;
1009
  d3_selection_enterPrototype.select = function(selector) {
1010
    var subgroups = [], subgroup, subnode, upgroup, group, node;
1011
    for (var j = -1, m = this.length; ++j < m; ) {
1012
      upgroup = (group = this[j]).update;
1013
      subgroups.push(subgroup = []);
1014
      subgroup.parentNode = group.parentNode;
1015
      for (var i = -1, n = group.length; ++i < n; ) {
1016
        if (node = group[i]) {
1017
          subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
1018
          subnode.__data__ = node.__data__;
1019
        } else {
1020
          subgroup.push(null);
1021
        }
1022
      }
1023
    }
1024
    return d3_selection(subgroups);
1025
  };
1026
  d3_selection_enterPrototype.insert = function(name, before) {
1027
    if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1028
    return d3_selectionPrototype.insert.call(this, name, before);
1029
  };
1030
  function d3_selection_enterInsertBefore(enter) {
1031
    var i0, j0;
1032
    return function(d, i, j) {
1033
      var group = enter[j].update, n = group.length, node;
1034
      if (j != j0) j0 = j, i0 = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1035
      if (i >= i0) i0 = i + 1;
0 ignored issues
show
Bug introduced by
The variable i0 does not seem to be initialized in case j != j0 on line 1034 is false. Are you sure this can never be the case?
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1036
      while (!(node = group[i0]) && ++i0 < n) ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
introduced by
The while loop does not have a body. Maybe you have misplaced a semicolon. If you do wish to have a loop without a body, use an empty body {}.
Loading history...
1037
      return node;
1038
    };
1039
  }
1040
  d3.select = function(node) {
1041
    var group;
1042
    if (typeof node === "string") {
1043
      group = [ d3_select(node, d3_document) ];
1044
      group.parentNode = d3_document.documentElement;
1045
    } else {
1046
      group = [ node ];
1047
      group.parentNode = d3_documentElement(node);
1048
    }
1049
    return d3_selection([ group ]);
1050
  };
1051
  d3.selectAll = function(nodes) {
1052
    var group;
1053
    if (typeof nodes === "string") {
1054
      group = d3_array(d3_selectAll(nodes, d3_document));
1055
      group.parentNode = d3_document.documentElement;
1056
    } else {
1057
      group = nodes;
1058
      group.parentNode = null;
1059
    }
1060
    return d3_selection([ group ]);
1061
  };
1062
  d3_selectionPrototype.on = function(type, listener, capture) {
1063
    var n = arguments.length;
1064
    if (n < 3) {
1065
      if (typeof type !== "string") {
1066
        if (n < 2) listener = false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1067
        for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1068
        return this;
1069
      }
1070
      if (n < 2) return (n = this.node()["__on" + type]) && n._;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1071
      capture = false;
1072
    }
1073
    return this.each(d3_selection_on(type, listener, capture));
1074
  };
1075
  function d3_selection_on(type, listener, capture) {
1076
    var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
1077
    if (i > 0) type = type.slice(0, i);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1078
    var filter = d3_selection_onFilters.get(type);
1079
    if (filter) type = filter, wrap = d3_selection_onFilter;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1080
    function onRemove() {
1081
      var l = this[name];
1082
      if (l) {
1083
        this.removeEventListener(type, l, l.$);
1084
        delete this[name];
1085
      }
1086
    }
1087
    function onAdd() {
1088
      var l = wrap(listener, d3_array(arguments));
1089
      onRemove.call(this);
1090
      this.addEventListener(type, this[name] = l, l.$ = capture);
1091
      l._ = listener;
1092
    }
1093
    function removeAll() {
1094
      var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
1095
      for (var name in this) {
1096
        if (match = name.match(re)) {
1097
          var l = this[name];
1098
          this.removeEventListener(match[1], l, l.$);
1099
          delete this[name];
1100
        }
1101
      }
1102
    }
1103
    return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
1104
  }
1105
  var d3_selection_onFilters = d3.map({
1106
    mouseenter: "mouseover",
1107
    mouseleave: "mouseout"
1108
  });
1109
  if (d3_document) {
1110
    d3_selection_onFilters.forEach(function(k) {
1111
      if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1112
    });
1113
  }
1114
  function d3_selection_onListener(listener, argumentz) {
1115
    return function(e) {
1116
      var o = d3.event;
1117
      d3.event = e;
1118
      argumentz[0] = this.__data__;
1119
      try {
1120
        listener.apply(this, argumentz);
1121
      } finally {
1122
        d3.event = o;
1123
      }
1124
    };
1125
  }
1126
  function d3_selection_onFilter(listener, argumentz) {
1127
    var l = d3_selection_onListener(listener, argumentz);
1128
    return function(e) {
1129
      var target = this, related = e.relatedTarget;
1130
      if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
1131
        l.call(target, e);
1132
      }
1133
    };
1134
  }
1135
  var d3_event_dragSelect, d3_event_dragId = 0;
1136
  function d3_event_dragSuppress(node) {
1137
    var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window(node)).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
1138
    if (d3_event_dragSelect == null) {
1139
      d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
1140
    }
1141
    if (d3_event_dragSelect) {
1142
      var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
1143
      style[d3_event_dragSelect] = "none";
1144
    }
1145
    return function(suppressClick) {
1146
      w.on(name, null);
1147
      if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
0 ignored issues
show
Bug introduced by
The variable select does not seem to be initialized in case d3_event_dragSelect on line 1141 is false. Are you sure this can never be the case?
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable style does not seem to be initialized in case d3_event_dragSelect on line 1141 is false. Are you sure this can never be the case?
Loading history...
1148
      if (suppressClick) {
1149
        var off = function() {
1150
          w.on(click, null);
1151
        };
1152
        w.on(click, function() {
1153
          d3_eventPreventDefault();
1154
          off();
1155
        }, true);
1156
        setTimeout(off, 0);
1157
      }
1158
    };
1159
  }
1160
  d3.mouse = function(container) {
1161
    return d3_mousePoint(container, d3_eventSource());
1162
  };
1163
  var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
1164
  function d3_mousePoint(container, e) {
1165
    if (e.changedTouches) e = e.changedTouches[0];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1166
    var svg = container.ownerSVGElement || container;
1167
    if (svg.createSVGPoint) {
1168
      var point = svg.createSVGPoint();
1169
      if (d3_mouse_bug44083 < 0) {
1170
        var window = d3_window(container);
1171
        if (window.scrollX || window.scrollY) {
1172
          svg = d3.select("body").append("svg").style({
1173
            position: "absolute",
1174
            top: 0,
1175
            left: 0,
1176
            margin: 0,
1177
            padding: 0,
1178
            border: "none"
1179
          }, "important");
1180
          var ctm = svg[0][0].getScreenCTM();
1181
          d3_mouse_bug44083 = !(ctm.f || ctm.e);
1182
          svg.remove();
1183
        }
1184
      }
1185
      if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX, 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1186
      point.y = e.clientY;
1187
      point = point.matrixTransform(container.getScreenCTM().inverse());
1188
      return [ point.x, point.y ];
1189
    }
1190
    var rect = container.getBoundingClientRect();
1191
    return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
1192
  }
1193
  d3.touch = function(container, touches, identifier) {
1194
    if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1195
    if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if touches is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1196
      if ((touch = touches[i]).identifier === identifier) {
1197
        return d3_mousePoint(container, touch);
1198
      }
1199
    }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
1200
  };
1201
  d3.behavior.drag = function() {
1202
    var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend");
1203
    function drag() {
1204
      this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
1205
    }
1206
    function dragstart(id, position, subject, move, end) {
1207
      return function() {
1208
        var that = this, target = d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
1209
        if (origin) {
1210
          dragOffset = origin.apply(that, arguments);
1211
          dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
1212
        } else {
1213
          dragOffset = [ 0, 0 ];
1214
        }
1215
        dispatch({
1216
          type: "dragstart"
1217
        });
1218
        function moved() {
1219
          var position1 = position(parent, dragId), dx, dy;
1220
          if (!position1) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1221
          dx = position1[0] - position0[0];
1222
          dy = position1[1] - position0[1];
1223
          dragged |= dx | dy;
1224
          position0 = position1;
1225
          dispatch({
1226
            type: "drag",
1227
            x: position1[0] + dragOffset[0],
1228
            y: position1[1] + dragOffset[1],
1229
            dx: dx,
1230
            dy: dy
1231
          });
1232
        }
1233
        function ended() {
1234
          if (!position(parent, dragId)) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1235
          dragSubject.on(move + dragName, null).on(end + dragName, null);
1236
          dragRestore(dragged && d3.event.target === target);
1237
          dispatch({
1238
            type: "dragend"
1239
          });
1240
        }
1241
      };
1242
    }
1243
    drag.origin = function(x) {
1244
      if (!arguments.length) return origin;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1245
      origin = x;
1246
      return drag;
1247
    };
1248
    return d3.rebind(drag, event, "on");
1249
  };
1250
  function d3_behavior_dragTouchId() {
1251
    return d3.event.changedTouches[0].identifier;
1252
  }
1253
  d3.touches = function(container, touches) {
1254
    if (arguments.length < 2) touches = d3_eventSource().touches;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1255
    return touches ? d3_array(touches).map(function(touch) {
1256
      var point = d3_mousePoint(container, touch);
1257
      point.identifier = touch.identifier;
1258
      return point;
1259
    }) : [];
1260
  };
1261
  var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
1262
  function d3_sgn(x) {
1263
    return x > 0 ? 1 : x < 0 ? -1 : 0;
1264
  }
1265
  function d3_cross2d(a, b, c) {
1266
    return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
1267
  }
1268
  function d3_acos(x) {
1269
    return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
1270
  }
1271
  function d3_asin(x) {
1272
    return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
1273
  }
1274
  function d3_sinh(x) {
1275
    return ((x = Math.exp(x)) - 1 / x) / 2;
1276
  }
1277
  function d3_cosh(x) {
1278
    return ((x = Math.exp(x)) + 1 / x) / 2;
1279
  }
1280
  function d3_tanh(x) {
1281
    return ((x = Math.exp(2 * x)) - 1) / (x + 1);
1282
  }
1283
  function d3_haversin(x) {
1284
    return (x = Math.sin(x / 2)) * x;
1285
  }
1286
  var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
1287
  d3.interpolateZoom = function(p0, p1) {
1288
    var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
1289
    var dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1), dr = r1 - r0, S = (dr || Math.log(w1 / w0)) / ρ;
1290
    function interpolate(t) {
1291
      var s = t * S;
1292
      if (dr) {
1293
        var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
1294
        return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
1295
      }
1296
      return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
1297
    }
1298
    interpolate.duration = S * 1e3;
1299
    return interpolate;
1300
  };
1301
  d3.behavior.zoom = function() {
1302
    var view = {
1303
      x: 0,
1304
      y: 0,
1305
      k: 1
1306
    }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
1307
    if (!d3_behavior_zoomWheel) {
1308
      d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1309
        return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
1310
      }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1311
        return d3.event.wheelDelta;
1312
      }, "mousewheel") : (d3_behavior_zoomDelta = function() {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1313
        return -d3.event.detail;
1314
      }, "MozMousePixelScroll");
1315
    }
1316
    function zoom(g) {
1317
      g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
1318
    }
1319
    zoom.event = function(g) {
1320
      g.each(function() {
1321
        var dispatch = event.of(this, arguments), view1 = view;
1322
        if (d3_transitionInheritId) {
1323
          d3.select(this).transition().each("start.zoom", function() {
1324
            view = this.__chart__ || {
1325
              x: 0,
1326
              y: 0,
1327
              k: 1
1328
            };
1329
            zoomstarted(dispatch);
1330
          }).tween("zoom:zoom", function() {
1331
            var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
1332
            return function(t) {
1333
              var l = i(t), k = dx / l[2];
1334
              this.__chart__ = view = {
1335
                x: cx - l[0] * k,
1336
                y: cy - l[1] * k,
1337
                k: k
1338
              };
1339
              zoomed(dispatch);
1340
            };
1341
          }).each("interrupt.zoom", function() {
1342
            zoomended(dispatch);
1343
          }).each("end.zoom", function() {
1344
            zoomended(dispatch);
1345
          });
1346
        } else {
1347
          this.__chart__ = view;
1348
          zoomstarted(dispatch);
1349
          zoomed(dispatch);
1350
          zoomended(dispatch);
1351
        }
1352
      });
1353
    };
1354
    zoom.translate = function(_) {
1355
      if (!arguments.length) return [ view.x, view.y ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1356
      view = {
1357
        x: +_[0],
1358
        y: +_[1],
1359
        k: view.k
1360
      };
1361
      rescale();
1362
      return zoom;
1363
    };
1364
    zoom.scale = function(_) {
1365
      if (!arguments.length) return view.k;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1366
      view = {
1367
        x: view.x,
1368
        y: view.y,
1369
        k: +_
1370
      };
1371
      rescale();
1372
      return zoom;
1373
    };
1374
    zoom.scaleExtent = function(_) {
1375
      if (!arguments.length) return scaleExtent;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1376
      scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
1377
      return zoom;
1378
    };
1379
    zoom.center = function(_) {
1380
      if (!arguments.length) return center;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1381
      center = _ && [ +_[0], +_[1] ];
1382
      return zoom;
1383
    };
1384
    zoom.size = function(_) {
1385
      if (!arguments.length) return size;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1386
      size = _ && [ +_[0], +_[1] ];
1387
      return zoom;
1388
    };
1389
    zoom.duration = function(_) {
1390
      if (!arguments.length) return duration;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1391
      duration = +_;
1392
      return zoom;
1393
    };
1394
    zoom.x = function(z) {
1395
      if (!arguments.length) return x1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1396
      x1 = z;
1397
      x0 = z.copy();
1398
      view = {
1399
        x: 0,
1400
        y: 0,
1401
        k: 1
1402
      };
1403
      return zoom;
1404
    };
1405
    zoom.y = function(z) {
1406
      if (!arguments.length) return y1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1407
      y1 = z;
1408
      y0 = z.copy();
1409
      view = {
1410
        x: 0,
1411
        y: 0,
1412
        k: 1
1413
      };
1414
      return zoom;
1415
    };
1416
    function location(p) {
1417
      return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
1418
    }
1419
    function point(l) {
1420
      return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
1421
    }
1422
    function scaleTo(s) {
1423
      view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
1424
    }
1425
    function translateTo(p, l) {
1426
      l = point(l);
1427
      view.x += p[0] - l[0];
1428
      view.y += p[1] - l[1];
1429
    }
1430
    function zoomTo(that, p, l, k) {
1431
      that.__chart__ = {
1432
        x: view.x,
1433
        y: view.y,
1434
        k: view.k
1435
      };
1436
      scaleTo(Math.pow(2, k));
1437
      translateTo(center0 = p, l);
1438
      that = d3.select(that);
1439
      if (duration > 0) that = that.transition().duration(duration);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1440
      that.call(zoom.event);
1441
    }
1442
    function rescale() {
1443
      if (x1) x1.domain(x0.range().map(function(x) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1444
        return (x - view.x) / view.k;
1445
      }).map(x0.invert));
1446
      if (y1) y1.domain(y0.range().map(function(y) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1447
        return (y - view.y) / view.k;
1448
      }).map(y0.invert));
1449
    }
1450
    function zoomstarted(dispatch) {
1451
      if (!zooming++) dispatch({
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1452
        type: "zoomstart"
1453
      });
1454
    }
1455
    function zoomed(dispatch) {
1456
      rescale();
1457
      dispatch({
1458
        type: "zoom",
1459
        scale: view.k,
1460
        translate: [ view.x, view.y ]
1461
      });
1462
    }
1463
    function zoomended(dispatch) {
1464
      if (!--zooming) dispatch({
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1465
        type: "zoomend"
1466
      });
1467
      center0 = null;
1468
    }
1469
    function mousedowned() {
1470
      var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
1471
      d3_selection_interrupt.call(that);
1472
      zoomstarted(dispatch);
1473
      function moved() {
1474
        dragged = 1;
1475
        translateTo(d3.mouse(that), location0);
1476
        zoomed(dispatch);
1477
      }
1478
      function ended() {
1479
        subject.on(mousemove, null).on(mouseup, null);
1480
        dragRestore(dragged && d3.event.target === target);
1481
        zoomended(dispatch);
1482
      }
1483
    }
1484
    function touchstarted() {
1485
      var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);
1486
      started();
1487
      zoomstarted(dispatch);
1488
      subject.on(mousedown, null).on(touchstart, started);
1489
      function relocate() {
1490
        var touches = d3.touches(that);
1491
        scale0 = view.k;
1492
        touches.forEach(function(t) {
1493
          if (t.identifier in locations0) locations0[t.identifier] = location(t);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1494
        });
1495
        return touches;
1496
      }
1497
      function started() {
1498
        var target = d3.event.target;
1499
        d3.select(target).on(touchmove, moved).on(touchend, ended);
1500
        targets.push(target);
1501
        var changed = d3.event.changedTouches;
1502
        for (var i = 0, n = changed.length; i < n; ++i) {
1503
          locations0[changed[i].identifier] = null;
1504
        }
1505
        var touches = relocate(), now = Date.now();
1506
        if (touches.length === 1) {
1507
          if (now - touchtime < 500) {
1508
            var p = touches[0];
1509
            zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
1510
            d3_eventPreventDefault();
1511
          }
1512
          touchtime = now;
1513
        } else if (touches.length > 1) {
1514
          var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable p already seems to be declared on line 1508. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1515
          distance0 = dx * dx + dy * dy;
1516
        }
1517
      }
1518
      function moved() {
1519
        var touches = d3.touches(that), p0, l0, p1, l1;
1520
        d3_selection_interrupt.call(that);
1521
        for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
1522
          p1 = touches[i];
1523
          if (l1 = locations0[p1.identifier]) {
1524
            if (l0) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1525
            p0 = p1, l0 = l1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1526
          }
1527
        }
1528
        if (l1) {
1529
          var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
0 ignored issues
show
Bug introduced by
The variable p0 seems to not be initialized for all possible execution paths.
Loading history...
Bug introduced by
The variable p1 seems to not be initialized for all possible execution paths.
Loading history...
1530
          p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
1531
          l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
0 ignored issues
show
Bug introduced by
The variable l0 seems to not be initialized for all possible execution paths.
Loading history...
1532
          scaleTo(scale1 * scale0);
1533
        }
1534
        touchtime = null;
1535
        translateTo(p0, l0);
1536
        zoomed(dispatch);
1537
      }
1538
      function ended() {
1539
        if (d3.event.touches.length) {
1540
          var changed = d3.event.changedTouches;
1541
          for (var i = 0, n = changed.length; i < n; ++i) {
1542
            delete locations0[changed[i].identifier];
1543
          }
1544
          for (var identifier in locations0) {
1545
            return void relocate();
1546
          }
1547
        }
1548
        d3.selectAll(targets).on(zoomName, null);
1549
        subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
1550
        dragRestore();
1551
        zoomended(dispatch);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
1552
      }
1553
    }
1554
    function mousewheeled() {
1555
      var dispatch = event.of(this, arguments);
1556
      if (mousewheelTimer) clearTimeout(mousewheelTimer); else translate0 = location(center0 = center || d3.mouse(this)), 
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1557
      d3_selection_interrupt.call(this), zoomstarted(dispatch);
1558
      mousewheelTimer = setTimeout(function() {
1559
        mousewheelTimer = null;
1560
        zoomended(dispatch);
1561
      }, 50);
1562
      d3_eventPreventDefault();
1563
      scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
1564
      translateTo(center0, translate0);
0 ignored issues
show
Bug introduced by
The variable center0 seems to not be initialized for all possible execution paths. Are you sure translateTo handles undefined variables?
Loading history...
Bug introduced by
The variable translate0 seems to not be initialized for all possible execution paths. Are you sure translateTo handles undefined variables?
Loading history...
1565
      zoomed(dispatch);
1566
    }
1567
    function dblclicked() {
1568
      var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
1569
      zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
1570
    }
1571
    return d3.rebind(zoom, event, "on");
1572
  };
1573
  var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
1574
  d3.color = d3_color;
1575
  function d3_color() {}
1576
  d3_color.prototype.toString = function() {
1577
    return this.rgb() + "";
1578
  };
1579
  d3.hsl = d3_hsl;
1580
  function d3_hsl(h, s, l) {
1581
    return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
By convention, constructors like d3_hsl should be capitalized.
Loading history...
1582
  }
1583
  var d3_hslPrototype = d3_hsl.prototype = new d3_color();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_color should be capitalized.
Loading history...
1584
  d3_hslPrototype.brighter = function(k) {
1585
    k = Math.pow(.7, arguments.length ? k : 1);
1586
    return new d3_hsl(this.h, this.s, this.l / k);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_hsl should be capitalized.
Loading history...
1587
  };
1588
  d3_hslPrototype.darker = function(k) {
1589
    k = Math.pow(.7, arguments.length ? k : 1);
1590
    return new d3_hsl(this.h, this.s, k * this.l);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_hsl should be capitalized.
Loading history...
1591
  };
1592
  d3_hslPrototype.rgb = function() {
1593
    return d3_hsl_rgb(this.h, this.s, this.l);
1594
  };
1595
  function d3_hsl_rgb(h, s, l) {
1596
    var m1, m2;
1597
    h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
1598
    s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
1599
    l = l < 0 ? 0 : l > 1 ? 1 : l;
1600
    m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
1601
    m1 = 2 * l - m2;
1602
    function v(h) {
1603
      if (h > 360) h -= 360; else if (h < 0) h += 360;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1604
      if (h < 60) return m1 + (m2 - m1) * h / 60;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1605
      if (h < 180) return m2;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1606
      if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1607
      return m1;
1608
    }
1609
    function vv(h) {
1610
      return Math.round(v(h) * 255);
1611
    }
1612
    return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_rgb should be capitalized.
Loading history...
1613
  }
1614
  d3.hcl = d3_hcl;
1615
  function d3_hcl(h, c, l) {
1616
    return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
By convention, constructors like d3_hcl should be capitalized.
Loading history...
1617
  }
1618
  var d3_hclPrototype = d3_hcl.prototype = new d3_color();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_color should be capitalized.
Loading history...
1619
  d3_hclPrototype.brighter = function(k) {
1620
    return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_hcl should be capitalized.
Loading history...
1621
  };
1622
  d3_hclPrototype.darker = function(k) {
1623
    return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_hcl should be capitalized.
Loading history...
1624
  };
1625
  d3_hclPrototype.rgb = function() {
1626
    return d3_hcl_lab(this.h, this.c, this.l).rgb();
1627
  };
1628
  function d3_hcl_lab(h, c, l) {
1629
    if (isNaN(h)) h = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1630
    if (isNaN(c)) c = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1631
    return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_lab should be capitalized.
Loading history...
1632
  }
1633
  d3.lab = d3_lab;
1634
  function d3_lab(l, a, b) {
1635
    return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_lab should be capitalized.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1636
  }
1637
  var d3_lab_K = 18;
1638
  var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1639
  var d3_labPrototype = d3_lab.prototype = new d3_color();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_color should be capitalized.
Loading history...
1640
  d3_labPrototype.brighter = function(k) {
1641
    return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_lab should be capitalized.
Loading history...
1642
  };
1643
  d3_labPrototype.darker = function(k) {
1644
    return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_lab should be capitalized.
Loading history...
1645
  };
1646
  d3_labPrototype.rgb = function() {
1647
    return d3_lab_rgb(this.l, this.a, this.b);
1648
  };
1649
  function d3_lab_rgb(l, a, b) {
1650
    var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1651
    x = d3_lab_xyz(x) * d3_lab_X;
1652
    y = d3_lab_xyz(y) * d3_lab_Y;
1653
    z = d3_lab_xyz(z) * d3_lab_Z;
1654
    return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_rgb should be capitalized.
Loading history...
1655
  }
1656
  function d3_lab_hcl(l, a, b) {
1657
    return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_hcl should be capitalized.
Loading history...
1658
  }
1659
  function d3_lab_xyz(x) {
1660
    return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1661
  }
1662
  function d3_xyz_lab(x) {
1663
    return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1664
  }
1665
  function d3_xyz_rgb(r) {
1666
    return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1667
  }
1668
  d3.rgb = d3_rgb;
1669
  function d3_rgb(r, g, b) {
1670
    return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_rgb should be capitalized.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1671
  }
1672
  function d3_rgbNumber(value) {
1673
    return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_rgb should be capitalized.
Loading history...
1674
  }
1675
  function d3_rgbString(value) {
1676
    return d3_rgbNumber(value) + "";
1677
  }
1678
  var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_color should be capitalized.
Loading history...
1679
  d3_rgbPrototype.brighter = function(k) {
1680
    k = Math.pow(.7, arguments.length ? k : 1);
1681
    var r = this.r, g = this.g, b = this.b, i = 30;
1682
    if (!r && !g && !b) return new d3_rgb(i, i, i);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Coding Style Best Practice introduced by
By convention, constructors like d3_rgb should be capitalized.
Loading history...
1683
    if (r && r < i) r = i;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1684
    if (g && g < i) g = i;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1685
    if (b && b < i) b = i;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1686
    return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_rgb should be capitalized.
Loading history...
1687
  };
1688
  d3_rgbPrototype.darker = function(k) {
1689
    k = Math.pow(.7, arguments.length ? k : 1);
1690
    return new d3_rgb(k * this.r, k * this.g, k * this.b);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_rgb should be capitalized.
Loading history...
1691
  };
1692
  d3_rgbPrototype.hsl = function() {
1693
    return d3_rgb_hsl(this.r, this.g, this.b);
1694
  };
1695
  d3_rgbPrototype.toString = function() {
1696
    return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
1697
  };
1698
  function d3_rgb_hex(v) {
1699
    return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
1700
  }
1701
  function d3_rgb_parse(format, rgb, hsl) {
1702
    var r = 0, g = 0, b = 0, m1, m2, color;
1703
    m1 = /([a-z]+)\((.*)\)/i.exec(format);
1704
    if (m1) {
1705
      m2 = m1[2].split(",");
1706
      switch (m1[1]) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1707
       case "hsl":
1708
        {
1709
          return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
1710
        }
1711
1712
       case "rgb":
1713
        {
1714
          return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
1715
        }
1716
      }
1717
    }
1718
    if (color = d3_rgb_names.get(format.toLowerCase())) {
1719
      return rgb(color.r, color.g, color.b);
1720
    }
1721
    if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
1722
      if (format.length === 4) {
1723
        r = (color & 3840) >> 4;
1724
        r = r >> 4 | r;
1725
        g = color & 240;
1726
        g = g >> 4 | g;
1727
        b = color & 15;
1728
        b = b << 4 | b;
1729
      } else if (format.length === 7) {
1730
        r = (color & 16711680) >> 16;
1731
        g = (color & 65280) >> 8;
1732
        b = color & 255;
1733
      }
1734
    }
1735
    return rgb(r, g, b);
1736
  }
1737
  function d3_rgb_hsl(r, g, b) {
1738
    var min = Math.min(r /= 255, g /= 255, b /= 255), max = Math.max(r, g, b), d = max - min, h, s, l = (max + min) / 2;
1739
    if (d) {
1740
      s = l < .5 ? d / (max + min) : d / (2 - max - min);
1741
      if (r == max) h = (g - b) / d + (g < b ? 6 : 0); else if (g == max) h = (b - r) / d + 2; else h = (r - g) / d + 4;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1742
      h *= 60;
1743
    } else {
1744
      h = NaN;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name NaN as h. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
1745
      s = l > 0 && l < 1 ? 0 : h;
1746
    }
1747
    return new d3_hsl(h, s, l);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_hsl should be capitalized.
Loading history...
1748
  }
1749
  function d3_rgb_lab(r, g, b) {
1750
    r = d3_rgb_xyz(r);
1751
    g = d3_rgb_xyz(g);
1752
    b = d3_rgb_xyz(b);
1753
    var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);
1754
    return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1755
  }
1756
  function d3_rgb_xyz(r) {
1757
    return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1758
  }
1759
  function d3_rgb_parseNumber(c) {
1760
    var f = parseFloat(c);
1761
    return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
1762
  }
1763
  var d3_rgb_names = d3.map({
1764
    aliceblue: 15792383,
1765
    antiquewhite: 16444375,
1766
    aqua: 65535,
1767
    aquamarine: 8388564,
1768
    azure: 15794175,
1769
    beige: 16119260,
1770
    bisque: 16770244,
1771
    black: 0,
1772
    blanchedalmond: 16772045,
1773
    blue: 255,
1774
    blueviolet: 9055202,
1775
    brown: 10824234,
1776
    burlywood: 14596231,
1777
    cadetblue: 6266528,
1778
    chartreuse: 8388352,
1779
    chocolate: 13789470,
1780
    coral: 16744272,
1781
    cornflowerblue: 6591981,
1782
    cornsilk: 16775388,
1783
    crimson: 14423100,
1784
    cyan: 65535,
1785
    darkblue: 139,
1786
    darkcyan: 35723,
1787
    darkgoldenrod: 12092939,
1788
    darkgray: 11119017,
1789
    darkgreen: 25600,
1790
    darkgrey: 11119017,
1791
    darkkhaki: 12433259,
1792
    darkmagenta: 9109643,
1793
    darkolivegreen: 5597999,
1794
    darkorange: 16747520,
1795
    darkorchid: 10040012,
1796
    darkred: 9109504,
1797
    darksalmon: 15308410,
1798
    darkseagreen: 9419919,
1799
    darkslateblue: 4734347,
1800
    darkslategray: 3100495,
1801
    darkslategrey: 3100495,
1802
    darkturquoise: 52945,
1803
    darkviolet: 9699539,
1804
    deeppink: 16716947,
1805
    deepskyblue: 49151,
1806
    dimgray: 6908265,
1807
    dimgrey: 6908265,
1808
    dodgerblue: 2003199,
1809
    firebrick: 11674146,
1810
    floralwhite: 16775920,
1811
    forestgreen: 2263842,
1812
    fuchsia: 16711935,
1813
    gainsboro: 14474460,
1814
    ghostwhite: 16316671,
1815
    gold: 16766720,
1816
    goldenrod: 14329120,
1817
    gray: 8421504,
1818
    green: 32768,
1819
    greenyellow: 11403055,
1820
    grey: 8421504,
1821
    honeydew: 15794160,
1822
    hotpink: 16738740,
1823
    indianred: 13458524,
1824
    indigo: 4915330,
1825
    ivory: 16777200,
1826
    khaki: 15787660,
1827
    lavender: 15132410,
1828
    lavenderblush: 16773365,
1829
    lawngreen: 8190976,
1830
    lemonchiffon: 16775885,
1831
    lightblue: 11393254,
1832
    lightcoral: 15761536,
1833
    lightcyan: 14745599,
1834
    lightgoldenrodyellow: 16448210,
1835
    lightgray: 13882323,
1836
    lightgreen: 9498256,
1837
    lightgrey: 13882323,
1838
    lightpink: 16758465,
1839
    lightsalmon: 16752762,
1840
    lightseagreen: 2142890,
1841
    lightskyblue: 8900346,
1842
    lightslategray: 7833753,
1843
    lightslategrey: 7833753,
1844
    lightsteelblue: 11584734,
1845
    lightyellow: 16777184,
1846
    lime: 65280,
1847
    limegreen: 3329330,
1848
    linen: 16445670,
1849
    magenta: 16711935,
1850
    maroon: 8388608,
1851
    mediumaquamarine: 6737322,
1852
    mediumblue: 205,
1853
    mediumorchid: 12211667,
1854
    mediumpurple: 9662683,
1855
    mediumseagreen: 3978097,
1856
    mediumslateblue: 8087790,
1857
    mediumspringgreen: 64154,
1858
    mediumturquoise: 4772300,
1859
    mediumvioletred: 13047173,
1860
    midnightblue: 1644912,
1861
    mintcream: 16121850,
1862
    mistyrose: 16770273,
1863
    moccasin: 16770229,
1864
    navajowhite: 16768685,
1865
    navy: 128,
1866
    oldlace: 16643558,
1867
    olive: 8421376,
1868
    olivedrab: 7048739,
1869
    orange: 16753920,
1870
    orangered: 16729344,
1871
    orchid: 14315734,
1872
    palegoldenrod: 15657130,
1873
    palegreen: 10025880,
1874
    paleturquoise: 11529966,
1875
    palevioletred: 14381203,
1876
    papayawhip: 16773077,
1877
    peachpuff: 16767673,
1878
    peru: 13468991,
1879
    pink: 16761035,
1880
    plum: 14524637,
1881
    powderblue: 11591910,
1882
    purple: 8388736,
1883
    rebeccapurple: 6697881,
1884
    red: 16711680,
1885
    rosybrown: 12357519,
1886
    royalblue: 4286945,
1887
    saddlebrown: 9127187,
1888
    salmon: 16416882,
1889
    sandybrown: 16032864,
1890
    seagreen: 3050327,
1891
    seashell: 16774638,
1892
    sienna: 10506797,
1893
    silver: 12632256,
1894
    skyblue: 8900331,
1895
    slateblue: 6970061,
1896
    slategray: 7372944,
1897
    slategrey: 7372944,
1898
    snow: 16775930,
1899
    springgreen: 65407,
1900
    steelblue: 4620980,
1901
    tan: 13808780,
1902
    teal: 32896,
1903
    thistle: 14204888,
1904
    tomato: 16737095,
1905
    turquoise: 4251856,
1906
    violet: 15631086,
1907
    wheat: 16113331,
1908
    white: 16777215,
1909
    whitesmoke: 16119285,
1910
    yellow: 16776960,
1911
    yellowgreen: 10145074
1912
  });
1913
  d3_rgb_names.forEach(function(key, value) {
1914
    d3_rgb_names.set(key, d3_rgbNumber(value));
1915
  });
1916
  function d3_functor(v) {
1917
    return typeof v === "function" ? v : function() {
1918
      return v;
1919
    };
1920
  }
1921
  d3.functor = d3_functor;
1922
  d3.xhr = d3_xhrType(d3_identity);
1923
  function d3_xhrType(response) {
1924
    return function(url, mimeType, callback) {
1925
      if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType, 
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1926
      mimeType = null;
1927
      return d3_xhr(url, mimeType, response, callback);
1928
    };
1929
  }
1930
  function d3_xhr(url, mimeType, response, callback) {
1931
    var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
0 ignored issues
show
Bug introduced by
The variable XMLHttpRequest seems to be never declared. If this is a global, consider adding a /** global: XMLHttpRequest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1932
    if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
0 ignored issues
show
Bug introduced by
The variable XDomainRequest seems to be never declared. If this is a global, consider adding a /** global: XDomainRequest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1933
    "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
1934
      request.readyState > 3 && respond();
1935
    };
1936
    function respond() {
1937
      var status = request.status, result;
1938
      if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
1939
        try {
1940
          result = response.call(xhr, request);
1941
        } catch (e) {
1942
          dispatch.error.call(xhr, e);
1943
          return;
1944
        }
1945
        dispatch.load.call(xhr, result);
1946
      } else {
1947
        dispatch.error.call(xhr, request);
1948
      }
1949
    }
1950
    request.onprogress = function(event) {
1951
      var o = d3.event;
1952
      d3.event = event;
1953
      try {
1954
        dispatch.progress.call(xhr, request);
1955
      } finally {
1956
        d3.event = o;
1957
      }
1958
    };
1959
    xhr.header = function(name, value) {
1960
      name = (name + "").toLowerCase();
1961
      if (arguments.length < 2) return headers[name];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1962
      if (value == null) delete headers[name]; else headers[name] = value + "";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1963
      return xhr;
1964
    };
1965
    xhr.mimeType = function(value) {
1966
      if (!arguments.length) return mimeType;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1967
      mimeType = value == null ? null : value + "";
1968
      return xhr;
1969
    };
1970
    xhr.responseType = function(value) {
1971
      if (!arguments.length) return responseType;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1972
      responseType = value;
1973
      return xhr;
1974
    };
1975
    xhr.response = function(value) {
1976
      response = value;
1977
      return xhr;
1978
    };
1979
    [ "get", "post" ].forEach(function(method) {
1980
      xhr[method] = function() {
1981
        return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
1982
      };
1983
    });
1984
    xhr.send = function(method, data, callback) {
1985
      if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1986
      request.open(method, url, true);
1987
      if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1988
      if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
1989
      if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1990
      if (responseType != null) request.responseType = responseType;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1991
      if (callback != null) xhr.on("error", callback).on("load", function(request) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1992
        callback(null, request);
1993
      });
1994
      dispatch.beforesend.call(xhr, request);
1995
      request.send(data == null ? null : data);
1996
      return xhr;
1997
    };
1998
    xhr.abort = function() {
1999
      request.abort();
2000
      return xhr;
2001
    };
2002
    d3.rebind(xhr, dispatch, "on");
2003
    return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
2004
  }
2005
  function d3_xhr_fixCallback(callback) {
2006
    return callback.length === 1 ? function(error, request) {
2007
      callback(error == null ? request : null);
2008
    } : callback;
2009
  }
2010
  function d3_xhrHasResponse(request) {
2011
    var type = request.responseType;
2012
    return type && type !== "text" ? request.response : request.responseText;
2013
  }
2014
  d3.dsv = function(delimiter, mimeType) {
2015
    var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
2016
    function dsv(url, row, callback) {
2017
      if (arguments.length < 3) callback = row, row = null;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2018
      var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
2019
      xhr.row = function(_) {
2020
        return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
2021
      };
2022
      return xhr;
2023
    }
2024
    function response(request) {
2025
      return dsv.parse(request.responseText);
2026
    }
2027
    function typedResponse(f) {
2028
      return function(request) {
2029
        return dsv.parse(request.responseText, f);
2030
      };
2031
    }
2032
    dsv.parse = function(text, f) {
2033
      var o;
2034
      return dsv.parseRows(text, function(row, i) {
2035
        if (o) return o(row, i - 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2036
        var a = new Function("d", "return {" + row.map(function(name, i) {
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
2037
          return JSON.stringify(name) + ": d[" + i + "]";
2038
        }).join(",") + "}");
2039
        o = f ? function(row, i) {
2040
          return f(a(row), i);
2041
        } : a;
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
2042
      });
2043
    };
2044
    dsv.parseRows = function(text, f) {
2045
      var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
2046
      function token() {
2047
        if (I >= N) return EOF;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2048
        if (eol) return eol = false, EOL;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2049
        var j = I;
2050
        if (text.charCodeAt(j) === 34) {
2051
          var i = j;
2052
          while (i++ < N) {
2053
            if (text.charCodeAt(i) === 34) {
2054
              if (text.charCodeAt(i + 1) !== 34) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2055
              ++i;
2056
            }
2057
          }
2058
          I = i + 2;
2059
          var c = text.charCodeAt(i + 1);
2060
          if (c === 13) {
2061
            eol = true;
2062
            if (text.charCodeAt(i + 2) === 10) ++I;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2063
          } else if (c === 10) {
2064
            eol = true;
2065
          }
2066
          return text.slice(j + 1, i).replace(/""/g, '"');
2067
        }
2068
        while (I < N) {
0 ignored issues
show
Bug introduced by
The variable I is changed as part of the while loop for example by I++ on line 2069. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
2069
          var c = text.charCodeAt(I++), k = 1;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable c already seems to be declared on line 2059. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
2070
          if (c === 10) eol = true; else if (c === 13) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2071
            eol = true;
2072
            if (text.charCodeAt(I) === 10) ++I, ++k;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2073
          } else if (c !== delimiterCode) continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2074
          return text.slice(j, I - k);
2075
        }
2076
        return text.slice(j);
2077
      }
2078
      while ((t = token()) !== EOF) {
2079
        var a = [];
2080
        while (t !== EOL && t !== EOF) {
2081
          a.push(t);
2082
          t = token();
2083
        }
2084
        if (f && (a = f(a, n++)) == null) continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2085
        rows.push(a);
2086
      }
2087
      return rows;
2088
    };
2089
    dsv.format = function(rows) {
2090
      if (Array.isArray(rows[0])) return dsv.formatRows(rows);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2091
      var fieldSet = new d3_Set(), fields = [];
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_Set should be capitalized.
Loading history...
2092
      rows.forEach(function(row) {
2093
        for (var field in row) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
2094
          if (!fieldSet.has(field)) {
2095
            fields.push(fieldSet.add(field));
2096
          }
2097
        }
2098
      });
2099
      return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
2100
        return fields.map(function(field) {
2101
          return formatValue(row[field]);
2102
        }).join(delimiter);
2103
      })).join("\n");
2104
    };
2105
    dsv.formatRows = function(rows) {
2106
      return rows.map(formatRow).join("\n");
2107
    };
2108
    function formatRow(row) {
2109
      return row.map(formatValue).join(delimiter);
2110
    }
2111
    function formatValue(text) {
2112
      return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
2113
    }
2114
    return dsv;
2115
  };
2116
  d3.csv = d3.dsv(",", "text/csv");
2117
  d3.tsv = d3.dsv("	", "text/tab-separated-values");
2118
  var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_active, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
2119
    setTimeout(callback, 17);
2120
  };
2121
  d3.timer = function(callback, delay, then) {
2122
    var n = arguments.length;
2123
    if (n < 2) delay = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2124
    if (n < 3) then = Date.now();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2125
    var time = then + delay, timer = {
2126
      c: callback,
2127
      t: time,
2128
      f: false,
2129
      n: null
2130
    };
2131
    if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2132
    d3_timer_queueTail = timer;
2133
    if (!d3_timer_interval) {
2134
      d3_timer_timeout = clearTimeout(d3_timer_timeout);
2135
      d3_timer_interval = 1;
2136
      d3_timer_frame(d3_timer_step);
2137
    }
2138
  };
2139
  function d3_timer_step() {
2140
    var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
2141
    if (delay > 24) {
2142
      if (isFinite(delay)) {
2143
        clearTimeout(d3_timer_timeout);
2144
        d3_timer_timeout = setTimeout(d3_timer_step, delay);
2145
      }
2146
      d3_timer_interval = 0;
2147
    } else {
2148
      d3_timer_interval = 1;
2149
      d3_timer_frame(d3_timer_step);
2150
    }
2151
  }
2152
  d3.timer.flush = function() {
2153
    d3_timer_mark();
2154
    d3_timer_sweep();
2155
  };
2156
  function d3_timer_mark() {
2157
    var now = Date.now();
2158
    d3_timer_active = d3_timer_queueHead;
2159
    while (d3_timer_active) {
0 ignored issues
show
Bug introduced by
The variable d3_timer_active is changed as part of the while loop for example by d3_timer_active.n on line 2161. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
2160
      if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2161
      d3_timer_active = d3_timer_active.n;
2162
    }
2163
    return now;
2164
  }
2165
  function d3_timer_sweep() {
2166
    var t0, t1 = d3_timer_queueHead, time = Infinity;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as time. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
2167
    while (t1) {
2168
      if (t1.f) {
2169
        t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
2170
      } else {
2171
        if (t1.t < time) time = t1.t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2172
        t1 = (t0 = t1).n;
2173
      }
2174
    }
2175
    d3_timer_queueTail = t0;
0 ignored issues
show
Comprehensibility Bug introduced by
The variable t0 does not seem to be initialized in case the while loop on line 2167 is not entered. Are you sure this can never be the case?
Loading history...
2176
    return time;
2177
  }
2178
  function d3_format_precision(x, p) {
2179
    return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
2180
  }
2181
  d3.round = function(x, n) {
2182
    return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
2183
  };
2184
  var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
2185
  d3.formatPrefix = function(value, precision) {
2186
    var i = 0;
2187
    if (value) {
2188
      if (value < 0) value *= -1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2189
      if (precision) value = d3.round(value, d3_format_precision(value, precision));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2190
      i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
2191
      i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
2192
    }
2193
    return d3_formatPrefixes[8 + i / 3];
2194
  };
2195
  function d3_formatPrefix(d, i) {
2196
    var k = Math.pow(10, abs(8 - i) * 3);
2197
    return {
2198
      scale: i > 8 ? function(d) {
2199
        return d / k;
2200
      } : function(d) {
2201
        return d * k;
2202
      },
2203
      symbol: d
2204
    };
2205
  }
2206
  function d3_locale_numberFormat(locale) {
2207
    var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {
2208
      var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
2209
      while (i > 0 && g > 0) {
2210
        if (length + g + 1 > width) g = Math.max(1, width - length);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2211
        t.push(value.substring(i -= g, i + g));
2212
        if ((length += g + 1) > width) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2213
        g = locale_grouping[j = (j + 1) % locale_grouping.length];
2214
      }
2215
      return t.reverse().join(locale_thousands);
2216
    } : d3_identity;
2217
    return function(specifier) {
2218
      var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true;
2219
      if (precision) precision = +precision.substring(1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2220
      if (zfill || fill === "0" && align === "=") {
2221
        zfill = fill = "0";
2222
        align = "=";
2223
      }
2224
      switch (type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
2225
       case "n":
2226
        comma = true;
2227
        type = "g";
2228
        break;
2229
2230
       case "%":
2231
        scale = 100;
2232
        suffix = "%";
2233
        type = "f";
2234
        break;
2235
2236
       case "p":
2237
        scale = 100;
2238
        suffix = "%";
2239
        type = "r";
2240
        break;
2241
2242
       case "b":
2243
       case "o":
2244
       case "x":
2245
       case "X":
2246
        if (symbol === "#") prefix = "0" + type.toLowerCase();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2247
2248
       case "c":
2249
        exponent = false;
2250
2251
       case "d":
2252
        integer = true;
2253
        precision = 0;
2254
        break;
2255
2256
       case "s":
2257
        scale = -1;
2258
        type = "r";
2259
        break;
2260
      }
2261
      if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2262
      if (type == "r" && !precision) type = "g";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2263
      if (precision != null) {
2264
        if (type == "g") precision = Math.max(1, Math.min(21, precision)); else if (type == "e" || type == "f") precision = Math.max(0, Math.min(20, precision));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2265
      }
2266
      type = d3_format_types.get(type) || d3_format_typeDefault;
2267
      var zcomma = zfill && comma;
2268
      return function(value) {
2269
        var fullSuffix = suffix;
2270
        if (integer && value % 1) return "";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2271
        var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2272
        if (scale < 0) {
2273
          var unit = d3.formatPrefix(value, precision);
2274
          value = unit.scale(value);
2275
          fullSuffix = unit.symbol + suffix;
2276
        } else {
2277
          value *= scale;
2278
        }
2279
        value = type(value, precision);
2280
        var i = value.lastIndexOf("."), before, after;
2281
        if (i < 0) {
2282
          var j = exponent ? value.lastIndexOf("e") : -1;
2283
          if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2284
        } else {
2285
          before = value.substring(0, i);
2286
          after = locale_decimal + value.substring(i + 1);
2287
        }
2288
        if (!zfill && comma) before = formatGroup(before, Infinity);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2289
        var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
2290
        if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2291
        negative += prefix;
2292
        value = before + after;
2293
        return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix;
2294
      };
2295
    };
2296
  }
2297
  var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
2298
  var d3_format_types = d3.map({
2299
    b: function(x) {
2300
      return x.toString(2);
2301
    },
2302
    c: function(x) {
2303
      return String.fromCharCode(x);
2304
    },
2305
    o: function(x) {
2306
      return x.toString(8);
2307
    },
2308
    x: function(x) {
2309
      return x.toString(16);
2310
    },
2311
    X: function(x) {
2312
      return x.toString(16).toUpperCase();
2313
    },
2314
    g: function(x, p) {
2315
      return x.toPrecision(p);
2316
    },
2317
    e: function(x, p) {
2318
      return x.toExponential(p);
2319
    },
2320
    f: function(x, p) {
2321
      return x.toFixed(p);
2322
    },
2323
    r: function(x, p) {
2324
      return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p))));
2325
    }
2326
  });
2327
  function d3_format_typeDefault(x) {
2328
    return x + "";
2329
  }
2330
  var d3_time = d3.time = {}, d3_date = Date;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Date as d3_date. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
2331
  function d3_date_utc() {
2332
    this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
2333
  }
2334
  d3_date_utc.prototype = {
2335
    getDate: function() {
2336
      return this._.getUTCDate();
2337
    },
2338
    getDay: function() {
2339
      return this._.getUTCDay();
2340
    },
2341
    getFullYear: function() {
2342
      return this._.getUTCFullYear();
2343
    },
2344
    getHours: function() {
2345
      return this._.getUTCHours();
2346
    },
2347
    getMilliseconds: function() {
2348
      return this._.getUTCMilliseconds();
2349
    },
2350
    getMinutes: function() {
2351
      return this._.getUTCMinutes();
2352
    },
2353
    getMonth: function() {
2354
      return this._.getUTCMonth();
2355
    },
2356
    getSeconds: function() {
2357
      return this._.getUTCSeconds();
2358
    },
2359
    getTime: function() {
2360
      return this._.getTime();
2361
    },
2362
    getTimezoneOffset: function() {
2363
      return 0;
2364
    },
2365
    valueOf: function() {
2366
      return this._.valueOf();
2367
    },
2368
    setDate: function() {
2369
      d3_time_prototype.setUTCDate.apply(this._, arguments);
2370
    },
2371
    setDay: function() {
2372
      d3_time_prototype.setUTCDay.apply(this._, arguments);
2373
    },
2374
    setFullYear: function() {
2375
      d3_time_prototype.setUTCFullYear.apply(this._, arguments);
2376
    },
2377
    setHours: function() {
2378
      d3_time_prototype.setUTCHours.apply(this._, arguments);
2379
    },
2380
    setMilliseconds: function() {
2381
      d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
2382
    },
2383
    setMinutes: function() {
2384
      d3_time_prototype.setUTCMinutes.apply(this._, arguments);
2385
    },
2386
    setMonth: function() {
2387
      d3_time_prototype.setUTCMonth.apply(this._, arguments);
2388
    },
2389
    setSeconds: function() {
2390
      d3_time_prototype.setUTCSeconds.apply(this._, arguments);
2391
    },
2392
    setTime: function() {
2393
      d3_time_prototype.setTime.apply(this._, arguments);
2394
    }
2395
  };
2396
  var d3_time_prototype = Date.prototype;
2397
  function d3_time_interval(local, step, number) {
2398
    function round(date) {
2399
      var d0 = local(date), d1 = offset(d0, 1);
2400
      return date - d0 < d1 - date ? d0 : d1;
2401
    }
2402
    function ceil(date) {
2403
      step(date = local(new d3_date(date - 1)), 1);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_date should be capitalized.
Loading history...
2404
      return date;
2405
    }
2406
    function offset(date, k) {
2407
      step(date = new d3_date(+date), k);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_date should be capitalized.
Loading history...
2408
      return date;
2409
    }
2410
    function range(t0, t1, dt) {
2411
      var time = ceil(t0), times = [];
2412
      if (dt > 1) {
2413
        while (time < t1) {
2414
          if (!(number(time) % dt)) times.push(new Date(+time));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2415
          step(time, 1);
2416
        }
2417
      } else {
2418
        while (time < t1) times.push(new Date(+time)), step(time, 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2419
      }
2420
      return times;
2421
    }
2422
    function range_utc(t0, t1, dt) {
2423
      try {
2424
        d3_date = d3_date_utc;
2425
        var utc = new d3_date_utc();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_date_utc should be capitalized.
Loading history...
2426
        utc._ = t0;
2427
        return range(utc, t1, dt);
2428
      } finally {
2429
        d3_date = Date;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Date as d3_date. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
2430
      }
2431
    }
2432
    local.floor = local;
2433
    local.round = round;
2434
    local.ceil = ceil;
2435
    local.offset = offset;
2436
    local.range = range;
2437
    var utc = local.utc = d3_time_interval_utc(local);
2438
    utc.floor = utc;
2439
    utc.round = d3_time_interval_utc(round);
2440
    utc.ceil = d3_time_interval_utc(ceil);
2441
    utc.offset = d3_time_interval_utc(offset);
2442
    utc.range = range_utc;
2443
    return local;
2444
  }
2445
  function d3_time_interval_utc(method) {
2446
    return function(date, k) {
2447
      try {
2448
        d3_date = d3_date_utc;
2449
        var utc = new d3_date_utc();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_date_utc should be capitalized.
Loading history...
2450
        utc._ = date;
2451
        return method(utc, k)._;
2452
      } finally {
2453
        d3_date = Date;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Date as d3_date. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
2454
      }
2455
    };
2456
  }
2457
  d3_time.year = d3_time_interval(function(date) {
2458
    date = d3_time.day(date);
2459
    date.setMonth(0, 1);
2460
    return date;
2461
  }, function(date, offset) {
2462
    date.setFullYear(date.getFullYear() + offset);
2463
  }, function(date) {
2464
    return date.getFullYear();
2465
  });
2466
  d3_time.years = d3_time.year.range;
2467
  d3_time.years.utc = d3_time.year.utc.range;
2468
  d3_time.day = d3_time_interval(function(date) {
2469
    var day = new d3_date(2e3, 0);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_date should be capitalized.
Loading history...
2470
    day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
2471
    return day;
2472
  }, function(date, offset) {
2473
    date.setDate(date.getDate() + offset);
2474
  }, function(date) {
2475
    return date.getDate() - 1;
2476
  });
2477
  d3_time.days = d3_time.day.range;
2478
  d3_time.days.utc = d3_time.day.utc.range;
2479
  d3_time.dayOfYear = function(date) {
2480
    var year = d3_time.year(date);
2481
    return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
2482
  };
2483
  [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
2484
    i = 7 - i;
2485
    var interval = d3_time[day] = d3_time_interval(function(date) {
2486
      (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
2487
      return date;
2488
    }, function(date, offset) {
2489
      date.setDate(date.getDate() + Math.floor(offset) * 7);
2490
    }, function(date) {
2491
      var day = d3_time.year(date).getDay();
2492
      return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
2493
    });
2494
    d3_time[day + "s"] = interval.range;
2495
    d3_time[day + "s"].utc = interval.utc.range;
2496
    d3_time[day + "OfYear"] = function(date) {
2497
      var day = d3_time.year(date).getDay();
2498
      return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
2499
    };
2500
  });
2501
  d3_time.week = d3_time.sunday;
2502
  d3_time.weeks = d3_time.sunday.range;
2503
  d3_time.weeks.utc = d3_time.sunday.utc.range;
2504
  d3_time.weekOfYear = d3_time.sundayOfYear;
2505
  function d3_locale_timeFormat(locale) {
2506
    var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;
2507
    function d3_time_format(template) {
2508
      var n = template.length;
2509
      function format(date) {
2510
        var string = [], i = -1, j = 0, c, p, f;
2511
        while (++i < n) {
2512
          if (template.charCodeAt(i) === 37) {
2513
            string.push(template.slice(j, i));
2514
            if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2515
            if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2516
            string.push(c);
2517
            j = i + 1;
2518
          }
2519
        }
2520
        string.push(template.slice(j, i));
2521
        return string.join("");
2522
      }
2523
      format.parse = function(string) {
2524
        var d = {
2525
          y: 1900,
2526
          m: 0,
2527
          d: 1,
2528
          H: 0,
2529
          M: 0,
2530
          S: 0,
2531
          L: 0,
2532
          Z: null
2533
        }, i = d3_time_parse(d, template, string, 0);
2534
        if (i != string.length) return null;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2535
        if ("p" in d) d.H = d.H % 12 + d.p * 12;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2536
        var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
2537
        if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2538
          date.setFullYear(d.y, 0, 1);
2539
          date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);
2540
        } else date.setFullYear(d.y, d.m, d.d);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2541
        date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
2542
        return localZ ? date._ : date;
2543
      };
2544
      format.toString = function() {
2545
        return template;
2546
      };
2547
      return format;
2548
    }
2549
    function d3_time_parse(date, template, string, j) {
2550
      var c, p, t, i = 0, n = template.length, m = string.length;
2551
      while (i < n) {
2552
        if (j >= m) return -1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2553
        c = template.charCodeAt(i++);
2554
        if (c === 37) {
2555
          t = template.charAt(i++);
2556
          p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
2557
          if (!p || (j = p(date, string, j)) < 0) return -1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2558
        } else if (c != string.charCodeAt(j++)) {
2559
          return -1;
2560
        }
2561
      }
2562
      return j;
2563
    }
2564
    d3_time_format.utc = function(template) {
2565
      var local = d3_time_format(template);
2566
      function format(date) {
2567
        try {
2568
          d3_date = d3_date_utc;
2569
          var utc = new d3_date();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_date should be capitalized.
Loading history...
2570
          utc._ = date;
2571
          return local(utc);
2572
        } finally {
2573
          d3_date = Date;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Date as d3_date. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
2574
        }
2575
      }
2576
      format.parse = function(string) {
2577
        try {
2578
          d3_date = d3_date_utc;
2579
          var date = local.parse(string);
2580
          return date && date._;
2581
        } finally {
2582
          d3_date = Date;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Date as d3_date. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
2583
        }
2584
      };
2585
      format.toString = local.toString;
2586
      return format;
2587
    };
2588
    d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
2589
    var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths);
2590
    locale_periods.forEach(function(p, i) {
2591
      d3_time_periodLookup.set(p.toLowerCase(), i);
2592
    });
2593
    var d3_time_formats = {
2594
      a: function(d) {
2595
        return locale_shortDays[d.getDay()];
2596
      },
2597
      A: function(d) {
2598
        return locale_days[d.getDay()];
2599
      },
2600
      b: function(d) {
2601
        return locale_shortMonths[d.getMonth()];
2602
      },
2603
      B: function(d) {
2604
        return locale_months[d.getMonth()];
2605
      },
2606
      c: d3_time_format(locale_dateTime),
2607
      d: function(d, p) {
2608
        return d3_time_formatPad(d.getDate(), p, 2);
2609
      },
2610
      e: function(d, p) {
2611
        return d3_time_formatPad(d.getDate(), p, 2);
2612
      },
2613
      H: function(d, p) {
2614
        return d3_time_formatPad(d.getHours(), p, 2);
2615
      },
2616
      I: function(d, p) {
2617
        return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
2618
      },
2619
      j: function(d, p) {
2620
        return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
2621
      },
2622
      L: function(d, p) {
2623
        return d3_time_formatPad(d.getMilliseconds(), p, 3);
2624
      },
2625
      m: function(d, p) {
2626
        return d3_time_formatPad(d.getMonth() + 1, p, 2);
2627
      },
2628
      M: function(d, p) {
2629
        return d3_time_formatPad(d.getMinutes(), p, 2);
2630
      },
2631
      p: function(d) {
2632
        return locale_periods[+(d.getHours() >= 12)];
2633
      },
2634
      S: function(d, p) {
2635
        return d3_time_formatPad(d.getSeconds(), p, 2);
2636
      },
2637
      U: function(d, p) {
2638
        return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
2639
      },
2640
      w: function(d) {
2641
        return d.getDay();
2642
      },
2643
      W: function(d, p) {
2644
        return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
2645
      },
2646
      x: d3_time_format(locale_date),
2647
      X: d3_time_format(locale_time),
2648
      y: function(d, p) {
2649
        return d3_time_formatPad(d.getFullYear() % 100, p, 2);
2650
      },
2651
      Y: function(d, p) {
2652
        return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
2653
      },
2654
      Z: d3_time_zone,
2655
      "%": function() {
2656
        return "%";
2657
      }
2658
    };
2659
    var d3_time_parsers = {
2660
      a: d3_time_parseWeekdayAbbrev,
2661
      A: d3_time_parseWeekday,
2662
      b: d3_time_parseMonthAbbrev,
2663
      B: d3_time_parseMonth,
2664
      c: d3_time_parseLocaleFull,
2665
      d: d3_time_parseDay,
2666
      e: d3_time_parseDay,
2667
      H: d3_time_parseHour24,
2668
      I: d3_time_parseHour24,
2669
      j: d3_time_parseDayOfYear,
2670
      L: d3_time_parseMilliseconds,
2671
      m: d3_time_parseMonthNumber,
2672
      M: d3_time_parseMinutes,
2673
      p: d3_time_parseAmPm,
2674
      S: d3_time_parseSeconds,
2675
      U: d3_time_parseWeekNumberSunday,
2676
      w: d3_time_parseWeekdayNumber,
2677
      W: d3_time_parseWeekNumberMonday,
2678
      x: d3_time_parseLocaleDate,
2679
      X: d3_time_parseLocaleTime,
2680
      y: d3_time_parseYear,
2681
      Y: d3_time_parseFullYear,
2682
      Z: d3_time_parseZone,
2683
      "%": d3_time_parseLiteralPercent
2684
    };
2685
    function d3_time_parseWeekdayAbbrev(date, string, i) {
2686
      d3_time_dayAbbrevRe.lastIndex = 0;
2687
      var n = d3_time_dayAbbrevRe.exec(string.slice(i));
2688
      return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2689
    }
2690
    function d3_time_parseWeekday(date, string, i) {
2691
      d3_time_dayRe.lastIndex = 0;
2692
      var n = d3_time_dayRe.exec(string.slice(i));
2693
      return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2694
    }
2695
    function d3_time_parseMonthAbbrev(date, string, i) {
2696
      d3_time_monthAbbrevRe.lastIndex = 0;
2697
      var n = d3_time_monthAbbrevRe.exec(string.slice(i));
2698
      return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2699
    }
2700
    function d3_time_parseMonth(date, string, i) {
2701
      d3_time_monthRe.lastIndex = 0;
2702
      var n = d3_time_monthRe.exec(string.slice(i));
2703
      return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2704
    }
2705
    function d3_time_parseLocaleFull(date, string, i) {
2706
      return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
2707
    }
2708
    function d3_time_parseLocaleDate(date, string, i) {
2709
      return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
2710
    }
2711
    function d3_time_parseLocaleTime(date, string, i) {
2712
      return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
2713
    }
2714
    function d3_time_parseAmPm(date, string, i) {
2715
      var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
2716
      return n == null ? -1 : (date.p = n, i);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2717
    }
2718
    return d3_time_format;
2719
  }
2720
  var d3_time_formatPads = {
2721
    "-": "",
2722
    _: " ",
2723
    "0": "0"
2724
  }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
2725
  function d3_time_formatPad(value, fill, width) {
2726
    var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
2727
    return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
2728
  }
2729
  function d3_time_formatRe(names) {
2730
    return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
2731
  }
2732
  function d3_time_formatLookup(names) {
2733
    var map = new d3_Map(), i = -1, n = names.length;
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_Map should be capitalized.
Loading history...
2734
    while (++i < n) map.set(names[i].toLowerCase(), i);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2735
    return map;
2736
  }
2737
  function d3_time_parseWeekdayNumber(date, string, i) {
2738
    d3_time_numberRe.lastIndex = 0;
2739
    var n = d3_time_numberRe.exec(string.slice(i, i + 1));
2740
    return n ? (date.w = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2741
  }
2742
  function d3_time_parseWeekNumberSunday(date, string, i) {
2743
    d3_time_numberRe.lastIndex = 0;
2744
    var n = d3_time_numberRe.exec(string.slice(i));
2745
    return n ? (date.U = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2746
  }
2747
  function d3_time_parseWeekNumberMonday(date, string, i) {
2748
    d3_time_numberRe.lastIndex = 0;
2749
    var n = d3_time_numberRe.exec(string.slice(i));
2750
    return n ? (date.W = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2751
  }
2752
  function d3_time_parseFullYear(date, string, i) {
2753
    d3_time_numberRe.lastIndex = 0;
2754
    var n = d3_time_numberRe.exec(string.slice(i, i + 4));
2755
    return n ? (date.y = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2756
  }
2757
  function d3_time_parseYear(date, string, i) {
2758
    d3_time_numberRe.lastIndex = 0;
2759
    var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2760
    return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2761
  }
2762
  function d3_time_parseZone(date, string, i) {
2763
    return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string, 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2764
    i + 5) : -1;
2765
  }
2766
  function d3_time_expandYear(d) {
2767
    return d + (d > 68 ? 1900 : 2e3);
2768
  }
2769
  function d3_time_parseMonthNumber(date, string, i) {
2770
    d3_time_numberRe.lastIndex = 0;
2771
    var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2772
    return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2773
  }
2774
  function d3_time_parseDay(date, string, i) {
2775
    d3_time_numberRe.lastIndex = 0;
2776
    var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2777
    return n ? (date.d = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2778
  }
2779
  function d3_time_parseDayOfYear(date, string, i) {
2780
    d3_time_numberRe.lastIndex = 0;
2781
    var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2782
    return n ? (date.j = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2783
  }
2784
  function d3_time_parseHour24(date, string, i) {
2785
    d3_time_numberRe.lastIndex = 0;
2786
    var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2787
    return n ? (date.H = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2788
  }
2789
  function d3_time_parseMinutes(date, string, i) {
2790
    d3_time_numberRe.lastIndex = 0;
2791
    var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2792
    return n ? (date.M = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2793
  }
2794
  function d3_time_parseSeconds(date, string, i) {
2795
    d3_time_numberRe.lastIndex = 0;
2796
    var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2797
    return n ? (date.S = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2798
  }
2799
  function d3_time_parseMilliseconds(date, string, i) {
2800
    d3_time_numberRe.lastIndex = 0;
2801
    var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2802
    return n ? (date.L = +n[0], i + n[0].length) : -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2803
  }
2804
  function d3_time_zone(d) {
2805
    var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
2806
    return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
2807
  }
2808
  function d3_time_parseLiteralPercent(date, string, i) {
2809
    d3_time_percentRe.lastIndex = 0;
2810
    var n = d3_time_percentRe.exec(string.slice(i, i + 1));
2811
    return n ? i + n[0].length : -1;
2812
  }
2813
  function d3_time_formatMulti(formats) {
2814
    var n = formats.length, i = -1;
2815
    while (++i < n) formats[i][0] = this(formats[i][0]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2816
    return function(date) {
2817
      var i = 0, f = formats[i];
2818
      while (!f[1](date)) f = formats[++i];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2819
      return f[0](date);
2820
    };
2821
  }
2822
  d3.locale = function(locale) {
2823
    return {
2824
      numberFormat: d3_locale_numberFormat(locale),
2825
      timeFormat: d3_locale_timeFormat(locale)
2826
    };
2827
  };
2828
  var d3_locale_enUS = d3.locale({
2829
    decimal: ".",
2830
    thousands: ",",
2831
    grouping: [ 3 ],
2832
    currency: [ "$", "" ],
2833
    dateTime: "%a %b %e %X %Y",
2834
    date: "%m/%d/%Y",
2835
    time: "%H:%M:%S",
2836
    periods: [ "AM", "PM" ],
2837
    days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
2838
    shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
2839
    months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
2840
    shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
2841
  });
2842
  d3.format = d3_locale_enUS.numberFormat;
2843
  d3.geo = {};
2844
  function d3_adder() {}
2845
  d3_adder.prototype = {
2846
    s: 0,
2847
    t: 0,
2848
    add: function(y) {
2849
      d3_adderSum(y, this.t, d3_adderTemp);
2850
      d3_adderSum(d3_adderTemp.s, this.s, this);
2851
      if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2852
    },
2853
    reset: function() {
2854
      this.s = this.t = 0;
2855
    },
2856
    valueOf: function() {
2857
      return this.s;
2858
    }
2859
  };
2860
  var d3_adderTemp = new d3_adder();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_adder should be capitalized.
Loading history...
2861
  function d3_adderSum(a, b, o) {
2862
    var x = o.s = a + b, bv = x - a, av = x - bv;
2863
    o.t = a - av + (b - bv);
2864
  }
2865
  d3.geo.stream = function(object, listener) {
2866
    if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
2867
      d3_geo_streamObjectType[object.type](object, listener);
2868
    } else {
2869
      d3_geo_streamGeometry(object, listener);
2870
    }
2871
  };
2872
  function d3_geo_streamGeometry(geometry, listener) {
2873
    if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
2874
      d3_geo_streamGeometryType[geometry.type](geometry, listener);
2875
    }
2876
  }
2877
  var d3_geo_streamObjectType = {
2878
    Feature: function(feature, listener) {
2879
      d3_geo_streamGeometry(feature.geometry, listener);
2880
    },
2881
    FeatureCollection: function(object, listener) {
2882
      var features = object.features, i = -1, n = features.length;
2883
      while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2884
    }
2885
  };
2886
  var d3_geo_streamGeometryType = {
2887
    Sphere: function(object, listener) {
2888
      listener.sphere();
2889
    },
2890
    Point: function(object, listener) {
2891
      object = object.coordinates;
2892
      listener.point(object[0], object[1], object[2]);
2893
    },
2894
    MultiPoint: function(object, listener) {
2895
      var coordinates = object.coordinates, i = -1, n = coordinates.length;
2896
      while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2897
    },
2898
    LineString: function(object, listener) {
2899
      d3_geo_streamLine(object.coordinates, listener, 0);
2900
    },
2901
    MultiLineString: function(object, listener) {
2902
      var coordinates = object.coordinates, i = -1, n = coordinates.length;
2903
      while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2904
    },
2905
    Polygon: function(object, listener) {
2906
      d3_geo_streamPolygon(object.coordinates, listener);
2907
    },
2908
    MultiPolygon: function(object, listener) {
2909
      var coordinates = object.coordinates, i = -1, n = coordinates.length;
2910
      while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2911
    },
2912
    GeometryCollection: function(object, listener) {
2913
      var geometries = object.geometries, i = -1, n = geometries.length;
2914
      while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2915
    }
2916
  };
2917
  function d3_geo_streamLine(coordinates, listener, closed) {
2918
    var i = -1, n = coordinates.length - closed, coordinate;
2919
    listener.lineStart();
2920
    while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2921
    listener.lineEnd();
2922
  }
2923
  function d3_geo_streamPolygon(coordinates, listener) {
2924
    var i = -1, n = coordinates.length;
2925
    listener.polygonStart();
2926
    while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
2927
    listener.polygonEnd();
2928
  }
2929
  d3.geo.area = function(object) {
2930
    d3_geo_areaSum = 0;
2931
    d3.geo.stream(object, d3_geo_area);
2932
    return d3_geo_areaSum;
2933
  };
2934
  var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_adder should be capitalized.
Loading history...
2935
  var d3_geo_area = {
2936
    sphere: function() {
2937
      d3_geo_areaSum += 4 * π;
2938
    },
2939
    point: d3_noop,
2940
    lineStart: d3_noop,
2941
    lineEnd: d3_noop,
2942
    polygonStart: function() {
2943
      d3_geo_areaRingSum.reset();
2944
      d3_geo_area.lineStart = d3_geo_areaRingStart;
2945
    },
2946
    polygonEnd: function() {
2947
      var area = 2 * d3_geo_areaRingSum;
2948
      d3_geo_areaSum += area < 0 ? 4 * π + area : area;
2949
      d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
2950
    }
2951
  };
2952
  function d3_geo_areaRingStart() {
2953
    var λ00, φ00, λ0, cosφ0, sinφ0;
2954
    d3_geo_area.point = function(λ, φ) {
2955
      d3_geo_area.point = nextPoint;
2956
      λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4), 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2957
      sinφ0 = Math.sin(φ);
2958
    };
2959
    function nextPoint(λ, φ) {
2960
      λ *= d3_radians;
2961
      φ = φ * d3_radians / 2 + π / 4;
2962
      var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
2963
      d3_geo_areaRingSum.add(Math.atan2(v, u));
2964
      λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
2965
    }
2966
    d3_geo_area.lineEnd = function() {
2967
      nextPoint(λ00, φ00);
2968
    };
2969
  }
2970
  function d3_geo_cartesian(spherical) {
2971
    var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
2972
    return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
2973
  }
2974
  function d3_geo_cartesianDot(a, b) {
2975
    return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2976
  }
2977
  function d3_geo_cartesianCross(a, b) {
2978
    return [ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0] ];
2979
  }
2980
  function d3_geo_cartesianAdd(a, b) {
2981
    a[0] += b[0];
2982
    a[1] += b[1];
2983
    a[2] += b[2];
2984
  }
2985
  function d3_geo_cartesianScale(vector, k) {
2986
    return [ vector[0] * k, vector[1] * k, vector[2] * k ];
2987
  }
2988
  function d3_geo_cartesianNormalize(d) {
2989
    var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
2990
    d[0] /= l;
2991
    d[1] /= l;
2992
    d[2] /= l;
2993
  }
2994
  function d3_geo_spherical(cartesian) {
2995
    return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
2996
  }
2997
  function d3_geo_sphericalEqual(a, b) {
2998
    return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
2999
  }
3000
  d3.geo.bounds = function() {
3001
    var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
3002
    var bound = {
3003
      point: point,
3004
      lineStart: lineStart,
3005
      lineEnd: lineEnd,
3006
      polygonStart: function() {
3007
        bound.point = ringPoint;
3008
        bound.lineStart = ringStart;
3009
        bound.lineEnd = ringEnd;
3010
        dλSum = 0;
3011
        d3_geo_area.polygonStart();
3012
      },
3013
      polygonEnd: function() {
3014
        d3_geo_area.polygonEnd();
3015
        bound.point = point;
3016
        bound.lineStart = lineStart;
3017
        bound.lineEnd = lineEnd;
3018
        if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3019
        range[0] = λ0, range[1] = λ1;
0 ignored issues
show
Bug introduced by
The variable λ1 seems to not be initialized for all possible execution paths.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Bug introduced by
The variable λ0 seems to not be initialized for all possible execution paths.
Loading history...
3020
      }
3021
    };
3022
    function point(λ, φ) {
3023
      ranges.push(range = [ λ0 = λ, λ1 = λ ]);
3024
      if (φ < φ0) φ0 = φ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3025
      if (φ > φ1) φ1 = φ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3026
    }
3027
    function linePoint(λ, φ) {
3028
      var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
3029
      if (p0) {
3030
        var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
3031
        d3_geo_cartesianNormalize(inflection);
3032
        inflection = d3_geo_spherical(inflection);
3033
        var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
3034
        if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
3035
          var φi = inflection[1] * d3_degrees;
3036
          if (φi > φ1) φ1 = φi;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3037
        } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3038
          var φi = -inflection[1] * d3_degrees;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable φi already seems to be declared on line 3035. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
3039
          if (φi < φ0) φ0 = φi;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3040
        } else {
3041
          if (φ < φ0) φ0 = φ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3042
          if (φ > φ1) φ1 = φ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3043
        }
3044
        if (antimeridian) {
3045
          if (λ < λ_) {
3046
            if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3047
          } else {
3048
            if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3049
          }
3050
        } else {
3051
          if (λ1 >= λ0) {
3052
            if (λ < λ0) λ0 = λ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3053
            if (λ > λ1) λ1 = λ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3054
          } else {
3055
            if (λ > λ_) {
3056
              if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3057
            } else {
3058
              if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3059
            }
3060
          }
3061
        }
3062
      } else {
3063
        point(λ, φ);
3064
      }
3065
      p0 = p, λ_ = λ;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3066
    }
3067
    function lineStart() {
3068
      bound.point = linePoint;
3069
    }
3070
    function lineEnd() {
3071
      range[0] = λ0, range[1] = λ1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3072
      bound.point = point;
3073
      p0 = null;
3074
    }
3075
    function ringPoint(λ, φ) {
3076
      if (p0) {
3077
        var dλ = λ - λ_;
3078
        dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
3079
      } else λ__ = λ, φ__ = φ;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3080
      d3_geo_area.point(λ, φ);
3081
      linePoint(λ, φ);
3082
    }
3083
    function ringStart() {
3084
      d3_geo_area.lineStart();
3085
    }
3086
    function ringEnd() {
3087
      ringPoint(λ__, φ__);
3088
      d3_geo_area.lineEnd();
3089
      if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3090
      range[0] = λ0, range[1] = λ1;
0 ignored issues
show
Bug introduced by
The variable λ0 does not seem to be initialized in case abs(dλSum) > ε on line 3089 is false. Are you sure this can never be the case?
Loading history...
Bug introduced by
The variable λ1 does not seem to be initialized in case abs(dλSum) > ε on line 3089 is false. Are you sure this can never be the case?
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3091
      p0 = null;
3092
    }
3093
    function angle(λ0, λ1) {
3094
      return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
3095
    }
3096
    function compareRanges(a, b) {
3097
      return a[0] - b[0];
3098
    }
3099
    function withinRange(x, range) {
3100
      return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
3101
    }
3102
    return function(feature) {
3103
      φ1 = λ1 = -(λ0 = φ0 = Infinity);
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as φ0. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
3104
      ranges = [];
3105
      d3.geo.stream(feature, bound);
3106
      var n = ranges.length;
3107
      if (n) {
3108
        ranges.sort(compareRanges);
3109
        for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
3110
          b = ranges[i];
3111
          if (withinRange(b[0], a) || withinRange(b[1], a)) {
3112
            if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3113
            if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3114
          } else {
3115
            merged.push(a = b);
3116
          }
3117
        }
3118
        var best = -Infinity, dλ;
3119
        for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable b already seems to be declared on line 3109. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Comprehensibility Naming Best Practice introduced by
The variable n already seems to be declared on line 3106. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 3109. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Comprehensibility Naming Best Practice introduced by
The variable a already seems to be declared on line 3109. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
3120
          b = merged[i];
3121
          if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3122
        }
3123
      }
3124
      ranges = range = null;
3125
      return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
3126
    };
3127
  }();
3128
  d3.geo.centroid = function(object) {
3129
    d3_geo_centroidW0 = d3_geo_centroidW1 = d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
3130
    d3.geo.stream(object, d3_geo_centroid);
3131
    var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
3132
    if (m < ε2) {
3133
      x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3134
      if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3135
      m = x * x + y * y + z * z;
3136
      if (m < ε2) return [ NaN, NaN ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3137
    }
3138
    return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
3139
  };
3140
  var d3_geo_centroidW0, d3_geo_centroidW1, d3_geo_centroidX0, d3_geo_centroidY0, d3_geo_centroidZ0, d3_geo_centroidX1, d3_geo_centroidY1, d3_geo_centroidZ1, d3_geo_centroidX2, d3_geo_centroidY2, d3_geo_centroidZ2;
3141
  var d3_geo_centroid = {
3142
    sphere: d3_noop,
3143
    point: d3_geo_centroidPoint,
3144
    lineStart: d3_geo_centroidLineStart,
3145
    lineEnd: d3_geo_centroidLineEnd,
3146
    polygonStart: function() {
3147
      d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
3148
    },
3149
    polygonEnd: function() {
3150
      d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
3151
    }
3152
  };
3153
  function d3_geo_centroidPoint(λ, φ) {
3154
    λ *= d3_radians;
3155
    var cosφ = Math.cos(φ *= d3_radians);
3156
    d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
3157
  }
3158
  function d3_geo_centroidPointXYZ(x, y, z) {
3159
    ++d3_geo_centroidW0;
3160
    d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
3161
    d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
3162
    d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
3163
  }
3164
  function d3_geo_centroidLineStart() {
3165
    var x0, y0, z0;
3166
    d3_geo_centroid.point = function(λ, φ) {
3167
      λ *= d3_radians;
3168
      var cosφ = Math.cos(φ *= d3_radians);
3169
      x0 = cosφ * Math.cos(λ);
3170
      y0 = cosφ * Math.sin(λ);
3171
      z0 = Math.sin(φ);
3172
      d3_geo_centroid.point = nextPoint;
3173
      d3_geo_centroidPointXYZ(x0, y0, z0);
3174
    };
3175 View Code Duplication
    function nextPoint(λ, φ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3176
      λ *= d3_radians;
3177
      var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), w = Math.atan2(Math.sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
3178
      d3_geo_centroidW1 += w;
3179
      d3_geo_centroidX1 += w * (x0 + (x0 = x));
3180
      d3_geo_centroidY1 += w * (y0 + (y0 = y));
3181
      d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3182
      d3_geo_centroidPointXYZ(x0, y0, z0);
3183
    }
3184
  }
3185
  function d3_geo_centroidLineEnd() {
3186
    d3_geo_centroid.point = d3_geo_centroidPoint;
3187
  }
3188
  function d3_geo_centroidRingStart() {
3189
    var λ00, φ00, x0, y0, z0;
3190
    d3_geo_centroid.point = function(λ, φ) {
3191
      λ00 = λ, φ00 = φ;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3192
      d3_geo_centroid.point = nextPoint;
3193
      λ *= d3_radians;
3194
      var cosφ = Math.cos(φ *= d3_radians);
3195
      x0 = cosφ * Math.cos(λ);
3196
      y0 = cosφ * Math.sin(λ);
3197
      z0 = Math.sin(φ);
3198
      d3_geo_centroidPointXYZ(x0, y0, z0);
3199
    };
3200
    d3_geo_centroid.lineEnd = function() {
3201
      nextPoint(λ00, φ00);
3202
      d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
3203
      d3_geo_centroid.point = d3_geo_centroidPoint;
3204
    };
3205 View Code Duplication
    function nextPoint(λ, φ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3206
      λ *= d3_radians;
3207
      var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), cx = y0 * z - z0 * y, cy = z0 * x - x0 * z, cz = x0 * y - y0 * x, m = Math.sqrt(cx * cx + cy * cy + cz * cz), u = x0 * x + y0 * y + z0 * z, v = m && -d3_acos(u) / m, w = Math.atan2(m, u);
3208
      d3_geo_centroidX2 += v * cx;
3209
      d3_geo_centroidY2 += v * cy;
3210
      d3_geo_centroidZ2 += v * cz;
3211
      d3_geo_centroidW1 += w;
3212
      d3_geo_centroidX1 += w * (x0 + (x0 = x));
3213
      d3_geo_centroidY1 += w * (y0 + (y0 = y));
3214
      d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3215
      d3_geo_centroidPointXYZ(x0, y0, z0);
3216
    }
3217
  }
3218
  function d3_geo_compose(a, b) {
3219
    function compose(x, y) {
3220
      return x = a(x, y), b(x[0], x[1]);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3221
    }
3222
    if (a.invert && b.invert) compose.invert = function(x, y) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3223
      return x = b.invert(x, y), x && a.invert(x[0], x[1]);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3224
    };
3225
    return compose;
3226
  }
3227
  function d3_true() {
3228
    return true;
3229
  }
3230
  function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
3231
    var subject = [], clip = [];
3232
    segments.forEach(function(segment) {
3233
      if ((n = segment.length - 1) <= 0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3234
      var n, p0 = segment[0], p1 = segment[n];
3235
      if (d3_geo_sphericalEqual(p0, p1)) {
3236
        listener.lineStart();
3237
        for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3238
        listener.lineEnd();
3239
        return;
3240
      }
3241
      var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geo_clipPolygonIntersection should be capitalized.
Loading history...
3242
      a.o = b;
3243
      subject.push(a);
3244
      clip.push(b);
3245
      a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geo_clipPolygonIntersection should be capitalized.
Loading history...
3246
      b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geo_clipPolygonIntersection should be capitalized.
Loading history...
3247
      a.o = b;
3248
      subject.push(a);
3249
      clip.push(b);
3250
    });
3251
    clip.sort(compare);
3252
    d3_geo_clipPolygonLinkCircular(subject);
3253
    d3_geo_clipPolygonLinkCircular(clip);
3254
    if (!subject.length) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3255
    for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
3256
      clip[i].e = entry = !entry;
3257
    }
3258
    var start = subject[0], points, point;
3259
    while (1) {
3260
      var current = start, isSubject = true;
3261
      while (current.v) if ((current = current.n) === start) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3262
      points = current.z;
3263
      listener.lineStart();
3264
      do {
3265
        current.v = current.o.v = true;
3266
        if (current.e) {
3267
          if (isSubject) {
3268
            for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 3255. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility Naming Best Practice introduced by
The variable n already seems to be declared on line 3255. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
3269
          } else {
3270
            interpolate(current.x, current.n.x, 1, listener);
3271
          }
3272
          current = current.n;
3273
        } else {
3274
          if (isSubject) {
3275
            points = current.p.z;
3276
            for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 3255. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3277
          } else {
3278
            interpolate(current.x, current.p.x, -1, listener);
3279
          }
3280
          current = current.p;
3281
        }
3282
        current = current.o;
3283
        points = current.z;
3284
        isSubject = !isSubject;
3285
      } while (!current.v);
3286
      listener.lineEnd();
3287
    }
3288
  }
3289
  function d3_geo_clipPolygonLinkCircular(array) {
3290
    if (!(n = array.length)) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3291
    var n, i = 0, a = array[0], b;
3292
    while (++i < n) {
3293
      a.n = b = array[i];
3294
      b.p = a;
3295
      a = b;
3296
    }
3297
    a.n = b = array[0];
3298
    b.p = a;
3299
  }
3300
  function d3_geo_clipPolygonIntersection(point, points, other, entry) {
3301
    this.x = point;
3302
    this.z = points;
3303
    this.o = other;
3304
    this.e = entry;
3305
    this.v = false;
3306
    this.n = this.p = null;
3307
  }
3308
  function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
3309
    return function(rotate, listener) {
3310
      var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
3311
      var clip = {
3312
        point: point,
3313
        lineStart: lineStart,
3314
        lineEnd: lineEnd,
3315
        polygonStart: function() {
3316
          clip.point = pointRing;
3317
          clip.lineStart = ringStart;
3318
          clip.lineEnd = ringEnd;
3319
          segments = [];
3320
          polygon = [];
3321
        },
3322
        polygonEnd: function() {
3323
          clip.point = point;
3324
          clip.lineStart = lineStart;
3325
          clip.lineEnd = lineEnd;
3326
          segments = d3.merge(segments);
3327
          var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
3328
          if (segments.length) {
3329
            if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3330
            d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
3331
          } else if (clipStartInside) {
3332
            if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3333
            listener.lineStart();
3334
            interpolate(null, null, 1, listener);
3335
            listener.lineEnd();
3336
          }
3337
          if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3338
          segments = polygon = null;
3339
        },
3340
        sphere: function() {
3341
          listener.polygonStart();
3342
          listener.lineStart();
3343
          interpolate(null, null, 1, listener);
3344
          listener.lineEnd();
3345
          listener.polygonEnd();
3346
        }
3347
      };
3348
      function point(λ, φ) {
3349
        var point = rotate(λ, φ);
3350
        if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3351
      }
3352
      function pointLine(λ, φ) {
3353
        var point = rotate(λ, φ);
3354
        line.point(point[0], point[1]);
3355
      }
3356
      function lineStart() {
3357
        clip.point = pointLine;
3358
        line.lineStart();
3359
      }
3360
      function lineEnd() {
3361
        clip.point = point;
3362
        line.lineEnd();
3363
      }
3364
      var segments;
3365
      var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
3366
      function pointRing(λ, φ) {
3367
        ring.push([ λ, φ ]);
3368
        var point = rotate(λ, φ);
3369
        ringListener.point(point[0], point[1]);
3370
      }
3371
      function ringStart() {
3372
        ringListener.lineStart();
3373
        ring = [];
3374
      }
3375
      function ringEnd() {
3376
        pointRing(ring[0][0], ring[0][1]);
3377
        ringListener.lineEnd();
3378
        var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
3379
        ring.pop();
3380
        polygon.push(ring);
3381
        ring = null;
3382
        if (!n) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3383
        if (clean & 1) {
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
3384
          segment = ringSegments[0];
3385
          var n = segment.length - 1, i = -1, point;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable n already seems to be declared on line 3378. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
3386
          if (n > 0) {
3387
            if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3388
            listener.lineStart();
3389
            while (++i < n) listener.point((point = segment[i])[0], point[1]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3390
            listener.lineEnd();
3391
          }
3392
          return;
3393
        }
3394
        if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
3395
        segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
3396
      }
3397
      return clip;
3398
    };
3399
  }
3400
  function d3_geo_clipSegmentLength1(segment) {
3401
    return segment.length > 1;
3402
  }
3403
  function d3_geo_clipBufferListener() {
3404
    var lines = [], line;
3405
    return {
3406
      lineStart: function() {
3407
        lines.push(line = []);
3408
      },
3409
      point: function(λ, φ) {
3410
        line.push([ λ, φ ]);
3411
      },
3412
      lineEnd: d3_noop,
3413
      buffer: function() {
3414
        var buffer = lines;
3415
        lines = [];
3416
        line = null;
3417
        return buffer;
3418
      },
3419
      rejoin: function() {
3420
        if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3421
      }
3422
    };
3423
  }
3424
  function d3_geo_clipSort(a, b) {
3425
    return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
3426
  }
3427
  var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
3428
  function d3_geo_clipAntimeridianLine(listener) {
3429
    var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name NaN as λ0. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
3430
    return {
3431
      lineStart: function() {
3432
        listener.lineStart();
3433
        clean = 1;
3434
      },
3435
      point: function(λ1, φ1) {
3436
        var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
3437
        if (abs(dλ - π) < ε) {
3438
          listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
3439
          listener.point(sλ0, φ0);
3440
          listener.lineEnd();
3441
          listener.lineStart();
3442
          listener.point(sλ1, φ0);
3443
          listener.point(λ1, φ0);
3444
          clean = 0;
3445
        } else if (sλ0 !== sλ1 && dλ >= π) {
3446
          if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3447
          if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3448
          φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
3449
          listener.point(sλ0, φ0);
3450
          listener.lineEnd();
3451
          listener.lineStart();
3452
          listener.point(sλ1, φ0);
3453
          clean = 0;
3454
        }
3455
        listener.point(λ0 = λ1, φ0 = φ1);
3456
        sλ0 = sλ1;
3457
      },
3458
      lineEnd: function() {
3459
        listener.lineEnd();
3460
        λ0 = φ0 = NaN;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name NaN as φ0. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
3461
      },
3462
      clean: function() {
3463
        return 2 - clean;
3464
      }
3465
    };
3466
  }
3467
  function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
3468
    var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
3469
    return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
3470
  }
3471
  function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
3472
    var φ;
3473
    if (from == null) {
3474
      φ = direction * halfπ;
3475
      listener.point(-π, φ);
3476
      listener.point(0, φ);
3477
      listener.point(π, φ);
3478
      listener.point(π, 0);
3479
      listener.point(π, -φ);
3480
      listener.point(0, -φ);
3481
      listener.point(-π, -φ);
3482
      listener.point(-π, 0);
3483
      listener.point(-π, φ);
3484
    } else if (abs(from[0] - to[0]) > ε) {
3485
      var s = from[0] < to[0] ? π : -π;
3486
      φ = direction * s / 2;
3487
      listener.point(-s, φ);
3488
      listener.point(0, φ);
3489
      listener.point(s, φ);
3490
    } else {
3491
      listener.point(to[0], to[1]);
3492
    }
3493
  }
3494
  function d3_geo_pointInPolygon(point, polygon) {
3495
    var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
3496
    d3_geo_areaRingSum.reset();
3497
    for (var i = 0, n = polygon.length; i < n; ++i) {
3498
      var ring = polygon[i], m = ring.length;
3499
      if (!m) continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3500
      var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
3501
      while (true) {
3502
        if (j === m) j = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3503
        point = ring[j];
3504
        var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;
3505
        d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
3506
        polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
3507
        if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
3508
          var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
3509
          d3_geo_cartesianNormalize(arc);
3510
          var intersection = d3_geo_cartesianCross(meridianNormal, arc);
3511
          d3_geo_cartesianNormalize(intersection);
3512
          var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
3513
          if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
3514
            winding += antimeridian ^ dλ >= 0 ? 1 : -1;
3515
          }
3516
        }
3517
        if (!j++) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3518
        λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3519
      }
3520
    }
3521
    return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
3522
  }
3523
  function d3_geo_clipCircle(radius) {
3524
    var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
3525
    return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
3526
    function visible(λ, φ) {
3527
      return Math.cos(λ) * Math.cos(φ) > cr;
3528
    }
3529
    function clipLine(listener) {
3530
      var point0, c0, v0, v00, clean;
3531
      return {
3532
        lineStart: function() {
3533
          v00 = v0 = false;
3534
          clean = 1;
3535
        },
3536
        point: function(λ, φ) {
3537
          var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
3538
          if (!point0 && (v00 = v0 = v)) listener.lineStart();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3539
          if (v !== v0) {
0 ignored issues
show
Bug introduced by
The variable v0 does not seem to be initialized in case !point0 && v00 = v0 = v on line 3538 is false. Are you sure this can never be the case?
Loading history...
3540
            point2 = intersect(point0, point1);
0 ignored issues
show
Bug introduced by
The variable point0 seems to not be initialized for all possible execution paths. Are you sure intersect handles undefined variables?
Loading history...
3541
            if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
3542
              point1[0] += ε;
3543
              point1[1] += ε;
3544
              v = visible(point1[0], point1[1]);
3545
            }
3546
          }
3547
          if (v !== v0) {
3548
            clean = 0;
3549
            if (v) {
3550
              listener.lineStart();
3551
              point2 = intersect(point1, point0);
3552
              listener.point(point2[0], point2[1]);
3553
            } else {
3554
              point2 = intersect(point0, point1);
3555
              listener.point(point2[0], point2[1]);
3556
              listener.lineEnd();
3557
            }
3558
            point0 = point2;
3559
          } else if (notHemisphere && point0 && smallRadius ^ v) {
3560
            var t;
3561
            if (!(c & c0) && (t = intersect(point1, point0, true))) {
3562
              clean = 0;
3563
              if (smallRadius) {
3564
                listener.lineStart();
3565
                listener.point(t[0][0], t[0][1]);
3566
                listener.point(t[1][0], t[1][1]);
3567
                listener.lineEnd();
3568
              } else {
3569
                listener.point(t[1][0], t[1][1]);
3570
                listener.lineEnd();
3571
                listener.lineStart();
3572
                listener.point(t[0][0], t[0][1]);
3573
              }
3574
            }
3575
          }
3576
          if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
3577
            listener.point(point1[0], point1[1]);
3578
          }
3579
          point0 = point1, v0 = v, c0 = c;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3580
        },
3581
        lineEnd: function() {
3582
          if (v0) listener.lineEnd();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3583
          point0 = null;
3584
        },
3585
        clean: function() {
3586
          return clean | (v00 && v0) << 1;
3587
        }
3588
      };
3589
    }
3590
    function intersect(a, b, two) {
3591
      var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
3592
      var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
3593
      if (!determinant) return !two && a;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3594
      var c1 = cr * n2n2 / determinant, c2 = -cr * n1n2 / determinant, n1xn2 = d3_geo_cartesianCross(n1, n2), A = d3_geo_cartesianScale(n1, c1), B = d3_geo_cartesianScale(n2, c2);
3595
      d3_geo_cartesianAdd(A, B);
3596
      var u = n1xn2, w = d3_geo_cartesianDot(A, u), uu = d3_geo_cartesianDot(u, u), t2 = w * w - uu * (d3_geo_cartesianDot(A, A) - 1);
3597
      if (t2 < 0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3598
      var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
3599
      d3_geo_cartesianAdd(q, A);
3600
      q = d3_geo_spherical(q);
3601
      if (!two) return q;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3602
      var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
3603
      if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3604
      var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
3605
      if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3606
      if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if meridian ? polar ? φ0 +... is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
3607
        var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
3608
        d3_geo_cartesianAdd(q1, A);
3609
        return [ q, d3_geo_spherical(q1) ];
3610
      }
3611
    }
3612
    function code(λ, φ) {
3613
      var r = smallRadius ? radius : π - radius, code = 0;
0 ignored issues
show
Bug introduced by
The variable radius seems to be never initialized.
Loading history...
3614
      if (λ < -r) code |= 1; else if (λ > r) code |= 2;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3615
      if (φ < -r) code |= 4; else if (φ > r) code |= 8;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3616
      return code;
3617
    }
3618
  }
3619
  function d3_geom_clipLine(x0, y0, x1, y1) {
3620
    return function(line) {
3621
      var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
3622
      r = x0 - ax;
3623
      if (!dx && r > 0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3624
      r /= dx;
3625
      if (dx < 0) {
3626
        if (r < t0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3627
        if (r < t1) t1 = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3628
      } else if (dx > 0) {
3629
        if (r > t1) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3630
        if (r > t0) t0 = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3631
      }
3632
      r = x1 - ax;
3633
      if (!dx && r < 0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3634
      r /= dx;
3635
      if (dx < 0) {
3636
        if (r > t1) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3637
        if (r > t0) t0 = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3638
      } else if (dx > 0) {
3639
        if (r < t0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3640
        if (r < t1) t1 = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3641
      }
3642
      r = y0 - ay;
3643
      if (!dy && r > 0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3644
      r /= dy;
3645
      if (dy < 0) {
3646
        if (r < t0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3647
        if (r < t1) t1 = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3648
      } else if (dy > 0) {
3649
        if (r > t1) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3650
        if (r > t0) t0 = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3651
      }
3652
      r = y1 - ay;
3653
      if (!dy && r < 0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3654
      r /= dy;
3655
      if (dy < 0) {
3656
        if (r > t1) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3657
        if (r > t0) t0 = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3658
      } else if (dy > 0) {
3659
        if (r < t0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3660
        if (r < t1) t1 = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3661
      }
3662
      if (t0 > 0) line.a = {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3663
        x: ax + t0 * dx,
3664
        y: ay + t0 * dy
3665
      };
3666
      if (t1 < 1) line.b = {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3667
        x: ax + t1 * dx,
3668
        y: ay + t1 * dy
3669
      };
3670
      return line;
3671
    };
3672
  }
3673
  var d3_geo_clipExtentMAX = 1e9;
3674
  d3.geo.clipExtent = function() {
3675
    var x0, y0, x1, y1, stream, clip, clipExtent = {
3676
      stream: function(output) {
3677
        if (stream) stream.valid = false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3678
        stream = clip(output);
3679
        stream.valid = true;
3680
        return stream;
3681
      },
3682
      extent: function(_) {
3683
        if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3684
        clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
3685
        if (stream) stream.valid = false, stream = null;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3686
        return clipExtent;
3687
      }
3688
    };
3689
    return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
3690
  };
3691
  function d3_geo_clipExtent(x0, y0, x1, y1) {
3692
    return function(listener) {
3693
      var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
3694
      var clip = {
3695
        point: point,
3696
        lineStart: lineStart,
3697
        lineEnd: lineEnd,
3698
        polygonStart: function() {
3699
          listener = bufferListener;
3700
          segments = [];
3701
          polygon = [];
3702
          clean = true;
3703
        },
3704
        polygonEnd: function() {
3705
          listener = listener_;
3706
          segments = d3.merge(segments);
3707
          var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
3708
          if (inside || visible) {
3709
            listener.polygonStart();
3710
            if (inside) {
3711
              listener.lineStart();
3712
              interpolate(null, null, 1, listener);
3713
              listener.lineEnd();
3714
            }
3715
            if (visible) {
3716
              d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
3717
            }
3718
            listener.polygonEnd();
3719
          }
3720
          segments = polygon = ring = null;
3721
        }
3722
      };
3723
      function insidePolygon(p) {
3724
        var wn = 0, n = polygon.length, y = p[1];
3725
        for (var i = 0; i < n; ++i) {
3726
          for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
3727
            b = v[j];
3728
            if (a[1] <= y) {
3729
              if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3730
            } else {
3731
              if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3732
            }
3733
            a = b;
3734
          }
3735
        }
3736
        return wn !== 0;
3737
      }
3738
      function interpolate(from, to, direction, listener) {
3739
        var a = 0, a1 = 0;
3740
        if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
3741
          do {
3742
            listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
3743
          } while ((a = (a + direction + 4) % 4) !== a1);
3744
        } else {
3745
          listener.point(to[0], to[1]);
3746
        }
3747
      }
3748
      function pointVisible(x, y) {
3749
        return x0 <= x && x <= x1 && y0 <= y && y <= y1;
3750
      }
3751
      function point(x, y) {
3752
        if (pointVisible(x, y)) listener.point(x, y);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3753
      }
3754
      var x__, y__, v__, x_, y_, v_, first, clean;
3755
      function lineStart() {
3756
        clip.point = linePoint;
3757
        if (polygon) polygon.push(ring = []);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3758
        first = true;
3759
        v_ = false;
3760
        x_ = y_ = NaN;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name NaN as y_. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
3761
      }
3762
      function lineEnd() {
3763
        if (segments) {
3764
          linePoint(x__, y__);
3765
          if (v__ && v_) bufferListener.rejoin();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3766
          segments.push(bufferListener.buffer());
3767
        }
3768
        clip.point = point;
3769
        if (v_) listener.lineEnd();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3770
      }
3771
      function linePoint(x, y) {
3772
        x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
3773
        y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
3774
        var v = pointVisible(x, y);
3775
        if (polygon) ring.push([ x, y ]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3776
        if (first) {
3777
          x__ = x, y__ = y, v__ = v;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3778
          first = false;
3779
          if (v) {
3780
            listener.lineStart();
3781
            listener.point(x, y);
3782
          }
3783
        } else {
3784
          if (v && v_) listener.point(x, y); else {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3785
            var l = {
3786
              a: {
3787
                x: x_,
3788
                y: y_
3789
              },
3790
              b: {
3791
                x: x,
3792
                y: y
3793
              }
3794
            };
3795
            if (clipLine(l)) {
3796
              if (!v_) {
3797
                listener.lineStart();
3798
                listener.point(l.a.x, l.a.y);
3799
              }
3800
              listener.point(l.b.x, l.b.y);
3801
              if (!v) listener.lineEnd();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3802
              clean = false;
3803
            } else if (v) {
3804
              listener.lineStart();
3805
              listener.point(x, y);
3806
              clean = false;
3807
            }
3808
          }
3809
        }
3810
        x_ = x, y_ = y, v_ = v;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3811
      }
3812
      return clip;
3813
    };
3814
    function corner(p, direction) {
3815
      return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
0 ignored issues
show
Bug introduced by
The variable x0 seems to be never initialized.
Loading history...
Bug introduced by
The variable y0 seems to be never initialized.
Loading history...
Bug introduced by
The variable x1 seems to be never initialized.
Loading history...
3816
    }
3817
    function compare(a, b) {
3818
      return comparePoints(a.x, b.x);
3819
    }
3820
    function comparePoints(a, b) {
3821
      var ca = corner(a, 1), cb = corner(b, 1);
3822
      return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
3823
    }
3824
  }
3825
  function d3_geo_conic(projectAt) {
3826
    var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
3827
    p.parallels = function(_) {
3828
      if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3829
      return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3830
    };
3831
    return p;
3832
  }
3833
  function d3_geo_conicEqualArea(φ0, φ1) {
3834
    var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
3835
    function forward(λ, φ) {
3836
      var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3837
      return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
3838
    }
3839
    forward.invert = function(x, y) {
3840
      var ρ0_y = ρ0 - y;
3841
      return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3842
    };
3843
    return forward;
3844
  }
3845
  (d3.geo.conicEqualArea = function() {
3846
    return d3_geo_conic(d3_geo_conicEqualArea);
3847
  }).raw = d3_geo_conicEqualArea;
3848
  d3.geo.albers = function() {
3849
    return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3850
  };
3851
  d3.geo.albersUsa = function() {
3852
    var lower48 = d3.geo.albers();
3853
    var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3854
    var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3855
    var point, pointStream = {
3856
      point: function(x, y) {
3857
        point = [ x, y ];
3858
      }
3859
    }, lower48Point, alaskaPoint, hawaiiPoint;
3860
    function albersUsa(coordinates) {
3861
      var x = coordinates[0], y = coordinates[1];
3862
      point = null;
3863
      (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3864
      return point;
3865
    }
3866
    albersUsa.invert = function(coordinates) {
3867
      var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3868
      return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3869
    };
3870
    albersUsa.stream = function(stream) {
3871
      var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3872
      return {
3873
        point: function(x, y) {
3874
          lower48Stream.point(x, y);
3875
          alaskaStream.point(x, y);
3876
          hawaiiStream.point(x, y);
3877
        },
3878
        sphere: function() {
3879
          lower48Stream.sphere();
3880
          alaskaStream.sphere();
3881
          hawaiiStream.sphere();
3882
        },
3883
        lineStart: function() {
3884
          lower48Stream.lineStart();
3885
          alaskaStream.lineStart();
3886
          hawaiiStream.lineStart();
3887
        },
3888
        lineEnd: function() {
3889
          lower48Stream.lineEnd();
3890
          alaskaStream.lineEnd();
3891
          hawaiiStream.lineEnd();
3892
        },
3893
        polygonStart: function() {
3894
          lower48Stream.polygonStart();
3895
          alaskaStream.polygonStart();
3896
          hawaiiStream.polygonStart();
3897
        },
3898
        polygonEnd: function() {
3899
          lower48Stream.polygonEnd();
3900
          alaskaStream.polygonEnd();
3901
          hawaiiStream.polygonEnd();
3902
        }
3903
      };
3904
    };
3905
    albersUsa.precision = function(_) {
3906
      if (!arguments.length) return lower48.precision();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3907
      lower48.precision(_);
3908
      alaska.precision(_);
3909
      hawaii.precision(_);
3910
      return albersUsa;
3911
    };
3912
    albersUsa.scale = function(_) {
3913
      if (!arguments.length) return lower48.scale();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3914
      lower48.scale(_);
3915
      alaska.scale(_ * .35);
3916
      hawaii.scale(_);
3917
      return albersUsa.translate(lower48.translate());
3918
    };
3919
    albersUsa.translate = function(_) {
3920
      if (!arguments.length) return lower48.translate();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3921
      var k = lower48.scale(), x = +_[0], y = +_[1];
3922
      lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3923
      alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3924
      hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3925
      return albersUsa;
3926
    };
3927
    return albersUsa.scale(1070);
3928
  };
3929
  var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3930
    point: d3_noop,
3931
    lineStart: d3_noop,
3932
    lineEnd: d3_noop,
3933
    polygonStart: function() {
3934
      d3_geo_pathAreaPolygon = 0;
3935
      d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3936
    },
3937
    polygonEnd: function() {
3938
      d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3939
      d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
3940
    }
3941
  };
3942
  function d3_geo_pathAreaRingStart() {
3943
    var x00, y00, x0, y0;
3944
    d3_geo_pathArea.point = function(x, y) {
3945
      d3_geo_pathArea.point = nextPoint;
3946
      x00 = x0 = x, y00 = y0 = y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3947
    };
3948
    function nextPoint(x, y) {
3949
      d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3950
      x0 = x, y0 = y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
3951
    }
3952
    d3_geo_pathArea.lineEnd = function() {
3953
      nextPoint(x00, y00);
3954
    };
3955
  }
3956
  var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3957
  var d3_geo_pathBounds = {
3958
    point: d3_geo_pathBoundsPoint,
3959
    lineStart: d3_noop,
3960
    lineEnd: d3_noop,
3961
    polygonStart: d3_noop,
3962
    polygonEnd: d3_noop
3963
  };
3964
  function d3_geo_pathBoundsPoint(x, y) {
3965
    if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3966
    if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3967
    if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3968
    if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
3969
  }
3970
  function d3_geo_pathBuffer() {
3971
    var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
3972
    var stream = {
3973
      point: point,
3974
      lineStart: function() {
3975
        stream.point = pointLineStart;
3976
      },
3977
      lineEnd: lineEnd,
3978
      polygonStart: function() {
3979
        stream.lineEnd = lineEndPolygon;
3980
      },
3981
      polygonEnd: function() {
3982
        stream.lineEnd = lineEnd;
3983
        stream.point = point;
3984
      },
3985
      pointRadius: function(_) {
3986
        pointCircle = d3_geo_pathBufferCircle(_);
3987
        return stream;
3988
      },
3989
      result: function() {
3990
        if (buffer.length) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if buffer.length is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
3991
          var result = buffer.join("");
3992
          buffer = [];
3993
          return result;
3994
        }
3995
      }
3996
    };
3997
    function point(x, y) {
3998
      buffer.push("M", x, ",", y, pointCircle);
3999
    }
4000
    function pointLineStart(x, y) {
4001
      buffer.push("M", x, ",", y);
4002
      stream.point = pointLine;
4003
    }
4004
    function pointLine(x, y) {
4005
      buffer.push("L", x, ",", y);
4006
    }
4007
    function lineEnd() {
4008
      stream.point = point;
4009
    }
4010
    function lineEndPolygon() {
4011
      buffer.push("Z");
4012
    }
4013
    return stream;
4014
  }
4015
  function d3_geo_pathBufferCircle(radius) {
4016
    return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
4017
  }
4018
  var d3_geo_pathCentroid = {
4019
    point: d3_geo_pathCentroidPoint,
4020
    lineStart: d3_geo_pathCentroidLineStart,
4021
    lineEnd: d3_geo_pathCentroidLineEnd,
4022
    polygonStart: function() {
4023
      d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
4024
    },
4025
    polygonEnd: function() {
4026
      d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4027
      d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
4028
      d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
4029
    }
4030
  };
4031
  function d3_geo_pathCentroidPoint(x, y) {
4032
    d3_geo_centroidX0 += x;
4033
    d3_geo_centroidY0 += y;
4034
    ++d3_geo_centroidZ0;
4035
  }
4036
  function d3_geo_pathCentroidLineStart() {
4037
    var x0, y0;
4038
    d3_geo_pathCentroid.point = function(x, y) {
4039
      d3_geo_pathCentroid.point = nextPoint;
4040
      d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4041
    };
4042
    function nextPoint(x, y) {
4043
      var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4044
      d3_geo_centroidX1 += z * (x0 + x) / 2;
4045
      d3_geo_centroidY1 += z * (y0 + y) / 2;
4046
      d3_geo_centroidZ1 += z;
4047
      d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4048
    }
4049
  }
4050
  function d3_geo_pathCentroidLineEnd() {
4051
    d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4052
  }
4053
  function d3_geo_pathCentroidRingStart() {
4054
    var x00, y00, x0, y0;
4055
    d3_geo_pathCentroid.point = function(x, y) {
4056
      d3_geo_pathCentroid.point = nextPoint;
4057
      d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
4058
    };
4059
    function nextPoint(x, y) {
4060
      var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4061
      d3_geo_centroidX1 += z * (x0 + x) / 2;
4062
      d3_geo_centroidY1 += z * (y0 + y) / 2;
4063
      d3_geo_centroidZ1 += z;
4064
      z = y0 * x - x0 * y;
4065
      d3_geo_centroidX2 += z * (x0 + x);
4066
      d3_geo_centroidY2 += z * (y0 + y);
4067
      d3_geo_centroidZ2 += z * 3;
4068
      d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4069
    }
4070
    d3_geo_pathCentroid.lineEnd = function() {
4071
      nextPoint(x00, y00);
4072
    };
4073
  }
4074
  function d3_geo_pathContext(context) {
4075
    var pointRadius = 4.5;
4076
    var stream = {
4077
      point: point,
4078
      lineStart: function() {
4079
        stream.point = pointLineStart;
4080
      },
4081
      lineEnd: lineEnd,
4082
      polygonStart: function() {
4083
        stream.lineEnd = lineEndPolygon;
4084
      },
4085
      polygonEnd: function() {
4086
        stream.lineEnd = lineEnd;
4087
        stream.point = point;
4088
      },
4089
      pointRadius: function(_) {
4090
        pointRadius = _;
4091
        return stream;
4092
      },
4093
      result: d3_noop
4094
    };
4095
    function point(x, y) {
4096
      context.moveTo(x + pointRadius, y);
4097
      context.arc(x, y, pointRadius, 0, τ);
4098
    }
4099
    function pointLineStart(x, y) {
4100
      context.moveTo(x, y);
4101
      stream.point = pointLine;
4102
    }
4103
    function pointLine(x, y) {
4104
      context.lineTo(x, y);
4105
    }
4106
    function lineEnd() {
4107
      stream.point = point;
4108
    }
4109
    function lineEndPolygon() {
4110
      context.closePath();
4111
    }
4112
    return stream;
4113
  }
4114
  function d3_geo_resample(project) {
4115
    var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
4116
    function resample(stream) {
4117
      return (maxDepth ? resampleRecursive : resampleNone)(stream);
4118
    }
4119
    function resampleNone(stream) {
4120
      return d3_geo_transformPoint(stream, function(x, y) {
4121
        x = project(x, y);
4122
        stream.point(x[0], x[1]);
4123
      });
4124
    }
4125
    function resampleRecursive(stream) {
4126
      var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
4127
      var resample = {
4128
        point: point,
4129
        lineStart: lineStart,
4130
        lineEnd: lineEnd,
4131
        polygonStart: function() {
4132
          stream.polygonStart();
4133
          resample.lineStart = ringStart;
4134
        },
4135
        polygonEnd: function() {
4136
          stream.polygonEnd();
4137
          resample.lineStart = lineStart;
4138
        }
4139
      };
4140
      function point(x, y) {
4141
        x = project(x, y);
4142
        stream.point(x[0], x[1]);
4143
      }
4144
      function lineStart() {
4145
        x0 = NaN;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name NaN as x0. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
4146
        resample.point = linePoint;
4147
        stream.lineStart();
4148
      }
4149
      function linePoint(λ, φ) {
4150
        var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
4151
        resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
4152
        stream.point(x0, y0);
4153
      }
4154
      function lineEnd() {
4155
        resample.point = point;
4156
        stream.lineEnd();
4157
      }
4158
      function ringStart() {
4159
        lineStart();
4160
        resample.point = ringPoint;
4161
        resample.lineEnd = ringEnd;
4162
      }
4163
      function ringPoint(λ, φ) {
4164
        linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Unused Code introduced by
The variable φ00 seems to be never used. Consider removing it.
Loading history...
4165
        resample.point = linePoint;
4166
      }
4167
      function ringEnd() {
4168
        resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
4169
        resample.lineEnd = lineEnd;
4170
        lineEnd();
4171
      }
4172
      return resample;
4173
    }
4174
    function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
4175
      var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
4176
      if (d2 > 4 * δ2 && depth--) {
4177
        var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = abs(abs(c) - 1) < ε || abs(λ0 - λ1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
4178
        if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
4179
          resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
4180
          stream.point(x2, y2);
4181
          resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
4182
        }
4183
      }
4184
    }
4185
    resample.precision = function(_) {
4186
      if (!arguments.length) return Math.sqrt(δ2);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4187
      maxDepth = (δ2 = _ * _) > 0 && 16;
4188
      return resample;
4189
    };
4190
    return resample;
4191
  }
4192
  d3.geo.path = function() {
4193
    var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
4194
    function path(object) {
4195
      if (object) {
4196
        if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4197
        if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4198
        d3.geo.stream(object, cacheStream);
4199
      }
4200
      return contextStream.result();
4201
    }
4202
    path.area = function(object) {
4203
      d3_geo_pathAreaSum = 0;
4204
      d3.geo.stream(object, projectStream(d3_geo_pathArea));
4205
      return d3_geo_pathAreaSum;
4206
    };
4207
    path.centroid = function(object) {
4208
      d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
4209
      d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
4210
      return d3_geo_centroidZ2 ? [ d3_geo_centroidX2 / d3_geo_centroidZ2, d3_geo_centroidY2 / d3_geo_centroidZ2 ] : d3_geo_centroidZ1 ? [ d3_geo_centroidX1 / d3_geo_centroidZ1, d3_geo_centroidY1 / d3_geo_centroidZ1 ] : d3_geo_centroidZ0 ? [ d3_geo_centroidX0 / d3_geo_centroidZ0, d3_geo_centroidY0 / d3_geo_centroidZ0 ] : [ NaN, NaN ];
4211
    };
4212
    path.bounds = function(object) {
4213
      d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as d3_geo_pathBoundsY0. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
4214
      d3.geo.stream(object, projectStream(d3_geo_pathBounds));
4215
      return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
4216
    };
4217
    path.projection = function(_) {
4218
      if (!arguments.length) return projection;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4219
      projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
4220
      return reset();
4221
    };
4222
    path.context = function(_) {
4223
      if (!arguments.length) return context;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4224
      contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geo_pathContext should be capitalized.
Loading history...
Coding Style Best Practice introduced by
By convention, constructors like d3_geo_pathBuffer should be capitalized.
Loading history...
4225
      if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4226
      return reset();
4227
    };
4228
    path.pointRadius = function(_) {
4229
      if (!arguments.length) return pointRadius;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4230
      pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4231
      return path;
4232
    };
4233
    function reset() {
4234
      cacheStream = null;
4235
      return path;
4236
    }
4237
    return path.projection(d3.geo.albersUsa()).context(null);
4238
  };
4239
  function d3_geo_pathProjectStream(project) {
4240
    var resample = d3_geo_resample(function(x, y) {
4241
      return project([ x * d3_degrees, y * d3_degrees ]);
4242
    });
4243
    return function(stream) {
4244
      return d3_geo_projectionRadians(resample(stream));
4245
    };
4246
  }
4247
  d3.geo.transform = function(methods) {
4248
    return {
4249
      stream: function(stream) {
4250
        var transform = new d3_geo_transform(stream);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geo_transform should be capitalized.
Loading history...
4251
        for (var k in methods) transform[k] = methods[k];
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4252
        return transform;
4253
      }
4254
    };
4255
  };
4256
  function d3_geo_transform(stream) {
4257
    this.stream = stream;
4258
  }
4259
  d3_geo_transform.prototype = {
4260
    point: function(x, y) {
4261
      this.stream.point(x, y);
4262
    },
4263
    sphere: function() {
4264
      this.stream.sphere();
4265
    },
4266
    lineStart: function() {
4267
      this.stream.lineStart();
4268
    },
4269
    lineEnd: function() {
4270
      this.stream.lineEnd();
4271
    },
4272
    polygonStart: function() {
4273
      this.stream.polygonStart();
4274
    },
4275
    polygonEnd: function() {
4276
      this.stream.polygonEnd();
4277
    }
4278
  };
4279
  function d3_geo_transformPoint(stream, point) {
4280
    return {
4281
      point: point,
4282
      sphere: function() {
4283
        stream.sphere();
4284
      },
4285
      lineStart: function() {
4286
        stream.lineStart();
4287
      },
4288
      lineEnd: function() {
4289
        stream.lineEnd();
4290
      },
4291
      polygonStart: function() {
4292
        stream.polygonStart();
4293
      },
4294
      polygonEnd: function() {
4295
        stream.polygonEnd();
4296
      }
4297
    };
4298
  }
4299
  d3.geo.projection = d3_geo_projection;
4300
  d3.geo.projectionMutator = d3_geo_projectionMutator;
4301
  function d3_geo_projection(project) {
4302
    return d3_geo_projectionMutator(function() {
4303
      return project;
4304
    })();
4305
  }
4306
  function d3_geo_projectionMutator(projectAt) {
4307
    var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
4308
      x = project(x, y);
4309
      return [ x[0] * k + δx, δy - x[1] * k ];
4310
    }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null, stream;
4311
    function projection(point) {
4312
      point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
4313
      return [ point[0] * k + δx, δy - point[1] * k ];
4314
    }
4315
    function invert(point) {
4316
      point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
4317
      return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
4318
    }
4319
    projection.stream = function(output) {
4320
      if (stream) stream.valid = false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4321
      stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
4322
      stream.valid = true;
4323
      return stream;
4324
    };
4325
    projection.clipAngle = function(_) {
4326
      if (!arguments.length) return clipAngle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4327
      preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4328
      return invalidate();
4329
    };
4330
    projection.clipExtent = function(_) {
4331
      if (!arguments.length) return clipExtent;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4332
      clipExtent = _;
4333
      postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
4334
      return invalidate();
4335
    };
4336
    projection.scale = function(_) {
4337
      if (!arguments.length) return k;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4338
      k = +_;
4339
      return reset();
4340
    };
4341
    projection.translate = function(_) {
4342
      if (!arguments.length) return [ x, y ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4343
      x = +_[0];
4344
      y = +_[1];
4345
      return reset();
4346
    };
4347
    projection.center = function(_) {
4348
      if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4349
      λ = _[0] % 360 * d3_radians;
4350
      φ = _[1] % 360 * d3_radians;
4351
      return reset();
4352
    };
4353
    projection.rotate = function(_) {
4354
      if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4355
      δλ = _[0] % 360 * d3_radians;
4356
      δφ = _[1] % 360 * d3_radians;
4357
      δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
4358
      return reset();
4359
    };
4360
    d3.rebind(projection, projectResample, "precision");
4361
    function reset() {
4362
      projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
4363
      var center = project(λ, φ);
4364
      δx = x - center[0] * k;
4365
      δy = y + center[1] * k;
4366
      return invalidate();
4367
    }
4368
    function invalidate() {
4369
      if (stream) stream.valid = false, stream = null;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4370
      return projection;
4371
    }
4372
    return function() {
4373
      project = projectAt.apply(this, arguments);
4374
      projection.invert = project.invert && invert;
4375
      return reset();
4376
    };
4377
  }
4378
  function d3_geo_projectionRadians(stream) {
4379
    return d3_geo_transformPoint(stream, function(x, y) {
4380
      stream.point(x * d3_radians, y * d3_radians);
4381
    });
4382
  }
4383
  function d3_geo_equirectangular(λ, φ) {
4384
    return [ λ, φ ];
4385
  }
4386
  (d3.geo.equirectangular = function() {
4387
    return d3_geo_projection(d3_geo_equirectangular);
4388
  }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
4389
  d3.geo.rotation = function(rotate) {
4390
    rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
4391
    function forward(coordinates) {
4392
      coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4393
      return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4394
    }
4395
    forward.invert = function(coordinates) {
4396
      coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4397
      return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4398
    };
4399
    return forward;
4400
  };
4401
  function d3_geo_identityRotation(λ, φ) {
4402
    return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4403
  }
4404
  d3_geo_identityRotation.invert = d3_geo_equirectangular;
4405
  function d3_geo_rotation(δλ, δφ, δγ) {
4406
    return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
4407
  }
4408
  function d3_geo_forwardRotationλ(δλ) {
4409
    return function(λ, φ) {
4410
      return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4411
    };
4412
  }
4413
  function d3_geo_rotationλ(δλ) {
4414
    var rotation = d3_geo_forwardRotationλ(δλ);
4415
    rotation.invert = d3_geo_forwardRotationλ(-δλ);
4416
    return rotation;
4417
  }
4418
  function d3_geo_rotationφγ(δφ, δγ) {
4419
    var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
4420
    function rotation(λ, φ) {
4421
      var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
4422
      return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
4423
    }
4424
    rotation.invert = function(λ, φ) {
4425
      var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
4426
      return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
4427
    };
4428
    return rotation;
4429
  }
4430
  d3.geo.circle = function() {
4431
    var origin = [ 0, 0 ], angle, precision = 6, interpolate;
4432
    function circle() {
4433
      var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert, ring = [];
4434
      interpolate(null, null, 1, {
4435
        point: function(x, y) {
4436
          ring.push(x = rotate(x, y));
4437
          x[0] *= d3_degrees, x[1] *= d3_degrees;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4438
        }
4439
      });
4440
      return {
4441
        type: "Polygon",
4442
        coordinates: [ ring ]
4443
      };
4444
    }
4445
    circle.origin = function(x) {
4446
      if (!arguments.length) return origin;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4447
      origin = x;
4448
      return circle;
4449
    };
4450
    circle.angle = function(x) {
4451
      if (!arguments.length) return angle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4452
      interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
4453
      return circle;
4454
    };
4455
    circle.precision = function(_) {
4456
      if (!arguments.length) return precision;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4457
      interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
4458
      return circle;
4459
    };
4460
    return circle.angle(90);
4461
  };
4462
  function d3_geo_circleInterpolate(radius, precision) {
4463
    var cr = Math.cos(radius), sr = Math.sin(radius);
4464
    return function(from, to, direction, listener) {
4465
      var step = direction * precision;
4466
      if (from != null) {
4467
        from = d3_geo_circleAngle(cr, from);
4468
        to = d3_geo_circleAngle(cr, to);
4469
        if (direction > 0 ? from < to : from > to) from += direction * τ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4470
      } else {
4471
        from = radius + direction * τ;
4472
        to = radius - .5 * step;
4473
      }
4474
      for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
4475
        listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
4476
      }
4477
    };
4478
  }
4479
  function d3_geo_circleAngle(cr, point) {
4480
    var a = d3_geo_cartesian(point);
4481
    a[0] -= cr;
4482
    d3_geo_cartesianNormalize(a);
4483
    var angle = d3_acos(-a[1]);
4484
    return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
4485
  }
4486
  d3.geo.distance = function(a, b) {
4487
    var Δλ = (b[0] - a[0]) * d3_radians, φ0 = a[1] * d3_radians, φ1 = b[1] * d3_radians, sinΔλ = Math.sin(Δλ), cosΔλ = Math.cos(Δλ), sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), t;
4488
    return Math.atan2(Math.sqrt((t = cosφ1 * sinΔλ) * t + (t = cosφ0 * sinφ1 - sinφ0 * cosφ1 * cosΔλ) * t), sinφ0 * sinφ1 + cosφ0 * cosφ1 * cosΔλ);
4489
  };
4490
  d3.geo.graticule = function() {
4491
    var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
4492
    function graticule() {
4493
      return {
4494
        type: "MultiLineString",
4495
        coordinates: lines()
4496
      };
4497
    }
4498
    function lines() {
4499
      return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) {
4500
        return abs(x % DX) > ε;
4501
      }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
4502
        return abs(y % DY) > ε;
4503
      }).map(y));
4504
    }
4505
    graticule.lines = function() {
4506
      return lines().map(function(coordinates) {
4507
        return {
4508
          type: "LineString",
4509
          coordinates: coordinates
4510
        };
4511
      });
4512
    };
4513
    graticule.outline = function() {
4514
      return {
4515
        type: "Polygon",
4516
        coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
4517
      };
4518
    };
4519
    graticule.extent = function(_) {
4520
      if (!arguments.length) return graticule.minorExtent();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4521
      return graticule.majorExtent(_).minorExtent(_);
4522
    };
4523 View Code Duplication
    graticule.majorExtent = function(_) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4524
      if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4525
      X0 = +_[0][0], X1 = +_[1][0];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4526
      Y0 = +_[0][1], Y1 = +_[1][1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4527
      if (X0 > X1) _ = X0, X0 = X1, X1 = _;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4528
      if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4529
      return graticule.precision(precision);
4530
    };
4531 View Code Duplication
    graticule.minorExtent = function(_) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4532
      if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4533
      x0 = +_[0][0], x1 = +_[1][0];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4534
      y0 = +_[0][1], y1 = +_[1][1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4535
      if (x0 > x1) _ = x0, x0 = x1, x1 = _;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4536
      if (y0 > y1) _ = y0, y0 = y1, y1 = _;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4537
      return graticule.precision(precision);
4538
    };
4539
    graticule.step = function(_) {
4540
      if (!arguments.length) return graticule.minorStep();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4541
      return graticule.majorStep(_).minorStep(_);
4542
    };
4543
    graticule.majorStep = function(_) {
4544
      if (!arguments.length) return [ DX, DY ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4545
      DX = +_[0], DY = +_[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4546
      return graticule;
4547
    };
4548
    graticule.minorStep = function(_) {
4549
      if (!arguments.length) return [ dx, dy ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4550
      dx = +_[0], dy = +_[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4551
      return graticule;
4552
    };
4553
    graticule.precision = function(_) {
4554
      if (!arguments.length) return precision;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4555
      precision = +_;
4556
      x = d3_geo_graticuleX(y0, y1, 90);
4557
      y = d3_geo_graticuleY(x0, x1, precision);
4558
      X = d3_geo_graticuleX(Y0, Y1, 90);
4559
      Y = d3_geo_graticuleY(X0, X1, precision);
4560
      return graticule;
4561
    };
4562
    return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
4563
  };
4564
  function d3_geo_graticuleX(y0, y1, dy) {
4565
    var y = d3.range(y0, y1 - ε, dy).concat(y1);
4566
    return function(x) {
4567
      return y.map(function(y) {
4568
        return [ x, y ];
4569
      });
4570
    };
4571
  }
4572
  function d3_geo_graticuleY(x0, x1, dx) {
4573
    var x = d3.range(x0, x1 - ε, dx).concat(x1);
4574
    return function(y) {
4575
      return x.map(function(x) {
4576
        return [ x, y ];
4577
      });
4578
    };
4579
  }
4580
  function d3_source(d) {
4581
    return d.source;
4582
  }
4583
  function d3_target(d) {
4584
    return d.target;
4585
  }
4586
  d3.geo.greatArc = function() {
4587
    var source = d3_source, source_, target = d3_target, target_;
4588
    function greatArc() {
4589
      return {
4590
        type: "LineString",
4591
        coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
4592
      };
4593
    }
4594
    greatArc.distance = function() {
4595
      return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
4596
    };
4597
    greatArc.source = function(_) {
4598
      if (!arguments.length) return source;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4599
      source = _, source_ = typeof _ === "function" ? null : _;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4600
      return greatArc;
4601
    };
4602
    greatArc.target = function(_) {
4603
      if (!arguments.length) return target;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4604
      target = _, target_ = typeof _ === "function" ? null : _;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4605
      return greatArc;
4606
    };
4607
    greatArc.precision = function() {
4608
      return arguments.length ? greatArc : 0;
4609
    };
4610
    return greatArc;
4611
  };
4612
  d3.geo.interpolate = function(source, target) {
4613
    return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
4614
  };
4615
  function d3_geo_interpolate(x0, y0, x1, y1) {
4616
    var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = 2 * Math.asin(Math.sqrt(d3_haversin(y1 - y0) + cy0 * cy1 * d3_haversin(x1 - x0))), k = 1 / Math.sin(d);
4617
    var interpolate = d ? function(t) {
4618
      var B = Math.sin(t *= d) * k, A = Math.sin(d - t) * k, x = A * kx0 + B * kx1, y = A * ky0 + B * ky1, z = A * sy0 + B * sy1;
4619
      return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
4620
    } : function() {
4621
      return [ x0 * d3_degrees, y0 * d3_degrees ];
4622
    };
4623
    interpolate.distance = d;
4624
    return interpolate;
4625
  }
4626
  d3.geo.length = function(object) {
4627
    d3_geo_lengthSum = 0;
4628
    d3.geo.stream(object, d3_geo_length);
4629
    return d3_geo_lengthSum;
4630
  };
4631
  var d3_geo_lengthSum;
4632
  var d3_geo_length = {
4633
    sphere: d3_noop,
4634
    point: d3_noop,
4635
    lineStart: d3_geo_lengthLineStart,
4636
    lineEnd: d3_noop,
4637
    polygonStart: d3_noop,
4638
    polygonEnd: d3_noop
4639
  };
4640
  function d3_geo_lengthLineStart() {
4641
    var λ0, sinφ0, cosφ0;
4642
    d3_geo_length.point = function(λ, φ) {
4643
      λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4644
      d3_geo_length.point = nextPoint;
4645
    };
4646
    d3_geo_length.lineEnd = function() {
4647
      d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
4648
    };
4649
    function nextPoint(λ, φ) {
4650
      var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
4651
      d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);
4652
      λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4653
    }
4654
  }
4655
  function d3_geo_azimuthal(scale, angle) {
4656
    function azimuthal(λ, φ) {
4657
      var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
4658
      return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
4659
    }
4660
    azimuthal.invert = function(x, y) {
4661
      var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
4662
      return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
4663
    };
4664
    return azimuthal;
4665
  }
4666
  var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
4667
    return Math.sqrt(2 / (1 + cosλcosφ));
4668
  }, function(ρ) {
4669
    return 2 * Math.asin(ρ / 2);
4670
  });
4671
  (d3.geo.azimuthalEqualArea = function() {
4672
    return d3_geo_projection(d3_geo_azimuthalEqualArea);
4673
  }).raw = d3_geo_azimuthalEqualArea;
4674
  var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
4675
    var c = Math.acos(cosλcosφ);
4676
    return c && c / Math.sin(c);
4677
  }, d3_identity);
4678
  (d3.geo.azimuthalEquidistant = function() {
4679
    return d3_geo_projection(d3_geo_azimuthalEquidistant);
4680
  }).raw = d3_geo_azimuthalEquidistant;
4681
  function d3_geo_conicConformal(φ0, φ1) {
4682
    var cosφ0 = Math.cos(φ0), t = function(φ) {
4683
      return Math.tan(π / 4 + φ / 2);
4684
    }, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;
4685
    if (!n) return d3_geo_mercator;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4686
    function forward(λ, φ) {
4687
      if (F > 0) {
4688
        if (φ < -halfπ + ε) φ = -halfπ + ε;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4689
      } else {
4690
        if (φ > halfπ - ε) φ = halfπ - ε;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4691
      }
4692
      var ρ = F / Math.pow(t(φ), n);
4693
      return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
4694
    }
4695
    forward.invert = function(x, y) {
4696
      var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
4697
      return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
4698
    };
4699
    return forward;
4700
  }
4701
  (d3.geo.conicConformal = function() {
4702
    return d3_geo_conic(d3_geo_conicConformal);
4703
  }).raw = d3_geo_conicConformal;
4704
  function d3_geo_conicEquidistant(φ0, φ1) {
4705
    var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
4706
    if (abs(n) < ε) return d3_geo_equirectangular;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4707
    function forward(λ, φ) {
4708
      var ρ = G - φ;
4709
      return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
4710
    }
4711
    forward.invert = function(x, y) {
4712
      var ρ0_y = G - y;
4713
      return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
4714
    };
4715
    return forward;
4716
  }
4717
  (d3.geo.conicEquidistant = function() {
4718
    return d3_geo_conic(d3_geo_conicEquidistant);
4719
  }).raw = d3_geo_conicEquidistant;
4720
  var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
4721
    return 1 / cosλcosφ;
4722
  }, Math.atan);
4723
  (d3.geo.gnomonic = function() {
4724
    return d3_geo_projection(d3_geo_gnomonic);
4725
  }).raw = d3_geo_gnomonic;
4726
  function d3_geo_mercator(λ, φ) {
4727
    return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
4728
  }
4729
  d3_geo_mercator.invert = function(x, y) {
4730
    return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
4731
  };
4732
  function d3_geo_mercatorProjection(project) {
4733
    var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
4734
    m.scale = function() {
4735
      var v = scale.apply(m, arguments);
4736
      return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4737
    };
4738
    m.translate = function() {
4739
      var v = translate.apply(m, arguments);
4740
      return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4741
    };
4742
    m.clipExtent = function(_) {
4743
      var v = clipExtent.apply(m, arguments);
4744
      if (v === m) {
4745
        if (clipAuto = _ == null) {
4746
          var k = π * scale(), t = translate();
4747
          clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
4748
        }
4749
      } else if (clipAuto) {
4750
        v = null;
4751
      }
4752
      return v;
4753
    };
4754
    return m.clipExtent(null);
4755
  }
4756
  (d3.geo.mercator = function() {
4757
    return d3_geo_mercatorProjection(d3_geo_mercator);
4758
  }).raw = d3_geo_mercator;
4759
  var d3_geo_orthographic = d3_geo_azimuthal(function() {
4760
    return 1;
4761
  }, Math.asin);
4762
  (d3.geo.orthographic = function() {
4763
    return d3_geo_projection(d3_geo_orthographic);
4764
  }).raw = d3_geo_orthographic;
4765
  var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
4766
    return 1 / (1 + cosλcosφ);
4767
  }, function(ρ) {
4768
    return 2 * Math.atan(ρ);
4769
  });
4770
  (d3.geo.stereographic = function() {
4771
    return d3_geo_projection(d3_geo_stereographic);
4772
  }).raw = d3_geo_stereographic;
4773
  function d3_geo_transverseMercator(λ, φ) {
4774
    return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
4775
  }
4776
  d3_geo_transverseMercator.invert = function(x, y) {
4777
    return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
4778
  };
4779
  (d3.geo.transverseMercator = function() {
4780
    var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
4781
    projection.center = function(_) {
4782
      return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4783
    };
4784
    projection.rotate = function(_) {
4785
      return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(), 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4786
      [ _[0], _[1], _[2] - 90 ]);
4787
    };
4788
    return rotate([ 0, 0, 90 ]);
4789
  }).raw = d3_geo_transverseMercator;
4790
  d3.geom = {};
4791
  function d3_geom_pointX(d) {
4792
    return d[0];
4793
  }
4794
  function d3_geom_pointY(d) {
4795
    return d[1];
4796
  }
4797
  d3.geom.hull = function(vertices) {
4798
    var x = d3_geom_pointX, y = d3_geom_pointY;
4799
    if (arguments.length) return hull(vertices);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4800
    function hull(data) {
4801
      if (data.length < 3) return [];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4802
      var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
4803
      for (i = 0; i < n; i++) {
4804
        points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
4805
      }
4806
      points.sort(d3_geom_hullOrder);
4807
      for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4808
      var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
4809
      var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
4810
      for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4811
      for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4812
      return polygon;
4813
    }
4814
    hull.x = function(_) {
4815
      return arguments.length ? (x = _, hull) : x;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4816
    };
4817
    hull.y = function(_) {
4818
      return arguments.length ? (y = _, hull) : y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
4819
    };
4820
    return hull;
4821
  };
4822
  function d3_geom_hullUpper(points) {
4823
    var n = points.length, hull = [ 0, 1 ], hs = 2;
4824
    for (var i = 2; i < n; i++) {
4825
      while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4826
      hull[hs++] = i;
4827
    }
4828
    return hull.slice(0, hs);
4829
  }
4830
  function d3_geom_hullOrder(a, b) {
4831
    return a[0] - b[0] || a[1] - b[1];
4832
  }
4833
  d3.geom.polygon = function(coordinates) {
4834
    d3_subclass(coordinates, d3_geom_polygonPrototype);
4835
    return coordinates;
4836
  };
4837
  var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
4838
  d3_geom_polygonPrototype.area = function() {
4839
    var i = -1, n = this.length, a, b = this[n - 1], area = 0;
4840
    while (++i < n) {
4841
      a = b;
4842
      b = this[i];
4843
      area += a[1] * b[0] - a[0] * b[1];
4844
    }
4845
    return area * .5;
4846
  };
4847
  d3_geom_polygonPrototype.centroid = function(k) {
4848
    var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
4849
    if (!arguments.length) k = -1 / (6 * this.area());
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4850
    while (++i < n) {
4851
      a = b;
4852
      b = this[i];
4853
      c = a[0] * b[1] - b[0] * a[1];
4854
      x += (a[0] + b[0]) * c;
4855
      y += (a[1] + b[1]) * c;
4856
    }
4857
    return [ x * k, y * k ];
4858
  };
4859
  d3_geom_polygonPrototype.clip = function(subject) {
4860
    var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d;
4861
    while (++i < n) {
4862
      input = subject.slice();
4863
      subject.length = 0;
4864
      b = this[i];
4865
      c = input[(m = input.length - closed) - 1];
4866
      j = -1;
4867
      while (++j < m) {
4868
        d = input[j];
4869
        if (d3_geom_polygonInside(d, a, b)) {
4870
          if (!d3_geom_polygonInside(c, a, b)) {
4871
            subject.push(d3_geom_polygonIntersect(c, d, a, b));
4872
          }
4873
          subject.push(d);
4874
        } else if (d3_geom_polygonInside(c, a, b)) {
4875
          subject.push(d3_geom_polygonIntersect(c, d, a, b));
4876
        }
4877
        c = d;
4878
      }
4879
      if (closed) subject.push(subject[0]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4880
      a = b;
4881
    }
4882
    return subject;
4883
  };
4884
  function d3_geom_polygonInside(p, a, b) {
4885
    return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
4886
  }
4887
  function d3_geom_polygonIntersect(c, d, a, b) {
4888
    var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21);
4889
    return [ x1 + ua * x21, y1 + ua * y21 ];
4890
  }
4891
  function d3_geom_polygonClosed(coordinates) {
4892
    var a = coordinates[0], b = coordinates[coordinates.length - 1];
4893
    return !(a[0] - b[0] || a[1] - b[1]);
4894
  }
4895
  var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
4896
  function d3_geom_voronoiBeach() {
4897
    d3_geom_voronoiRedBlackNode(this);
4898
    this.edge = this.site = this.circle = null;
4899
  }
4900
  function d3_geom_voronoiCreateBeach(site) {
4901
    var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiBeach should be capitalized.
Loading history...
4902
    beach.site = site;
4903
    return beach;
4904
  }
4905
  function d3_geom_voronoiDetachBeach(beach) {
4906
    d3_geom_voronoiDetachCircle(beach);
4907
    d3_geom_voronoiBeaches.remove(beach);
4908
    d3_geom_voronoiBeachPool.push(beach);
4909
    d3_geom_voronoiRedBlackNode(beach);
4910
  }
4911
  function d3_geom_voronoiRemoveBeach(beach) {
4912
    var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
4913
      x: x,
4914
      y: y
4915
    }, previous = beach.P, next = beach.N, disappearing = [ beach ];
4916
    d3_geom_voronoiDetachBeach(beach);
4917
    var lArc = previous;
4918
    while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
4919
      previous = lArc.P;
4920
      disappearing.unshift(lArc);
4921
      d3_geom_voronoiDetachBeach(lArc);
4922
      lArc = previous;
4923
    }
4924
    disappearing.unshift(lArc);
4925
    d3_geom_voronoiDetachCircle(lArc);
4926
    var rArc = next;
4927
    while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
4928
      next = rArc.N;
4929
      disappearing.push(rArc);
4930
      d3_geom_voronoiDetachBeach(rArc);
4931
      rArc = next;
4932
    }
4933
    disappearing.push(rArc);
4934
    d3_geom_voronoiDetachCircle(rArc);
4935
    var nArcs = disappearing.length, iArc;
4936
    for (iArc = 1; iArc < nArcs; ++iArc) {
4937
      rArc = disappearing[iArc];
4938
      lArc = disappearing[iArc - 1];
4939
      d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
4940
    }
4941
    lArc = disappearing[0];
4942
    rArc = disappearing[nArcs - 1];
4943
    rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
4944
    d3_geom_voronoiAttachCircle(lArc);
4945
    d3_geom_voronoiAttachCircle(rArc);
4946
  }
4947
  function d3_geom_voronoiAddBeach(site) {
4948
    var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
4949
    while (node) {
4950
      dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
4951
      if (dxl > ε) node = node.L; else {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4952
        dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
4953
        if (dxr > ε) {
4954
          if (!node.R) {
4955
            lArc = node;
4956
            break;
4957
          }
4958
          node = node.R;
4959
        } else {
4960
          if (dxl > -ε) {
4961
            lArc = node.P;
4962
            rArc = node;
4963
          } else if (dxr > -ε) {
4964
            lArc = node;
4965
            rArc = node.N;
4966
          } else {
4967
            lArc = rArc = node;
4968
          }
4969
          break;
4970
        }
4971
      }
4972
    }
4973
    var newArc = d3_geom_voronoiCreateBeach(site);
4974
    d3_geom_voronoiBeaches.insert(lArc, newArc);
0 ignored issues
show
Bug introduced by
The variable lArc seems to not be initialized for all possible execution paths. Are you sure insert handles undefined variables?
Loading history...
4975
    if (!lArc && !rArc) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4976
    if (lArc === rArc) {
0 ignored issues
show
Bug introduced by
The variable rArc seems to not be initialized for all possible execution paths.
Loading history...
4977
      d3_geom_voronoiDetachCircle(lArc);
4978
      rArc = d3_geom_voronoiCreateBeach(lArc.site);
4979
      d3_geom_voronoiBeaches.insert(newArc, rArc);
4980
      newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4981
      d3_geom_voronoiAttachCircle(lArc);
4982
      d3_geom_voronoiAttachCircle(rArc);
4983
      return;
4984
    }
4985
    if (!rArc) {
4986
      newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4987
      return;
4988
    }
4989
    d3_geom_voronoiDetachCircle(lArc);
4990
    d3_geom_voronoiDetachCircle(rArc);
4991
    var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
4992
      x: (cy * hb - by * hc) / d + ax,
4993
      y: (bx * hc - cx * hb) / d + ay
4994
    };
4995
    d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
4996
    newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
4997
    rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
4998
    d3_geom_voronoiAttachCircle(lArc);
4999
    d3_geom_voronoiAttachCircle(rArc);
5000
  }
5001
  function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
5002
    var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
5003
    if (!pby2) return rfocx;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5004
    var lArc = arc.P;
5005
    if (!lArc) return -Infinity;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5006
    site = lArc.site;
5007
    var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
5008
    if (!plby2) return lfocx;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5009
    var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
5010
    if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5011
    return (rfocx + lfocx) / 2;
5012
  }
5013
  function d3_geom_voronoiRightBreakPoint(arc, directrix) {
5014
    var rArc = arc.N;
5015
    if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5016
    var site = arc.site;
5017
    return site.y === directrix ? site.x : Infinity;
5018
  }
5019
  function d3_geom_voronoiCell(site) {
5020
    this.site = site;
5021
    this.edges = [];
5022
  }
5023
  d3_geom_voronoiCell.prototype.prepare = function() {
5024
    var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
5025
    while (iHalfEdge--) {
5026
      edge = halfEdges[iHalfEdge].edge;
5027
      if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5028
    }
5029
    halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
5030
    return halfEdges.length;
5031
  };
5032
  function d3_geom_voronoiCloseCells(extent) {
5033
    var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
5034
    while (iCell--) {
5035
      cell = cells[iCell];
5036
      if (!cell || !cell.prepare()) continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5037
      halfEdges = cell.edges;
5038
      nHalfEdges = halfEdges.length;
5039
      iHalfEdge = 0;
5040
      while (iHalfEdge < nHalfEdges) {
5041
        end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5042
        start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5043
        if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
5044
          halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiHalfEdge should be capitalized.
Loading history...
5045
            x: x0,
5046
            y: abs(x2 - x0) < ε ? y2 : y1
5047
          } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
5048
            x: abs(y2 - y1) < ε ? x2 : x1,
5049
            y: y1
5050
          } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
5051
            x: x1,
5052
            y: abs(x2 - x1) < ε ? y2 : y0
5053
          } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
5054
            x: abs(y2 - y0) < ε ? x2 : x0,
5055
            y: y0
5056
          } : null), cell.site, null));
5057
          ++nHalfEdges;
5058
        }
5059
      }
5060
    }
5061
  }
5062
  function d3_geom_voronoiHalfEdgeOrder(a, b) {
5063
    return b.angle - a.angle;
5064
  }
5065
  function d3_geom_voronoiCircle() {
5066
    d3_geom_voronoiRedBlackNode(this);
5067
    this.x = this.y = this.arc = this.site = this.cy = null;
5068
  }
5069
  function d3_geom_voronoiAttachCircle(arc) {
5070
    var lArc = arc.P, rArc = arc.N;
5071
    if (!lArc || !rArc) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5072
    var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
5073
    if (lSite === rSite) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5074
    var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
5075
    var d = 2 * (ax * cy - ay * cx);
5076
    if (d >= -ε2) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5077
    var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable cy already seems to be declared on line 5074. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
5078
    var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiCircle should be capitalized.
Loading history...
5079
    circle.arc = arc;
5080
    circle.site = cSite;
5081
    circle.x = x + bx;
5082
    circle.y = cy + Math.sqrt(x * x + y * y);
5083
    circle.cy = cy;
5084
    arc.circle = circle;
5085
    var before = null, node = d3_geom_voronoiCircles._;
5086
    while (node) {
5087
      if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
5088
        if (node.L) node = node.L; else {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5089
          before = node.P;
5090
          break;
5091
        }
5092
      } else {
5093
        if (node.R) node = node.R; else {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5094
          before = node;
5095
          break;
5096
        }
5097
      }
5098
    }
5099
    d3_geom_voronoiCircles.insert(before, circle);
5100
    if (!before) d3_geom_voronoiFirstCircle = circle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5101
  }
5102
  function d3_geom_voronoiDetachCircle(arc) {
5103
    var circle = arc.circle;
5104
    if (circle) {
5105
      if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5106
      d3_geom_voronoiCircles.remove(circle);
5107
      d3_geom_voronoiCirclePool.push(circle);
5108
      d3_geom_voronoiRedBlackNode(circle);
5109
      arc.circle = null;
5110
    }
5111
  }
5112
  function d3_geom_voronoiClipEdges(extent) {
5113
    var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
5114
    while (i--) {
5115
      e = edges[i];
5116
      if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
5117
        e.a = e.b = null;
5118
        edges.splice(i, 1);
5119
      }
5120
    }
5121
  }
5122
  function d3_geom_voronoiConnectEdge(edge, extent) {
5123
    var vb = edge.b;
5124
    if (vb) return true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5125
    var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
5126
    if (ry === ly) {
5127
      if (fx < x0 || fx >= x1) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5128
      if (lx > rx) {
5129
        if (!va) va = {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5130
          x: fx,
5131
          y: y0
5132
        }; else if (va.y >= y1) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5133
        vb = {
5134
          x: fx,
5135
          y: y1
5136
        };
5137
      } else {
5138
        if (!va) va = {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5139
          x: fx,
5140
          y: y1
5141
        }; else if (va.y < y0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5142
        vb = {
5143
          x: fx,
5144
          y: y0
5145
        };
5146
      }
5147
    } else {
5148
      fm = (lx - rx) / (ry - ly);
5149
      fb = fy - fm * fx;
5150
      if (fm < -1 || fm > 1) {
5151
        if (lx > rx) {
5152
          if (!va) va = {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5153
            x: (y0 - fb) / fm,
5154
            y: y0
5155
          }; else if (va.y >= y1) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5156
          vb = {
5157
            x: (y1 - fb) / fm,
5158
            y: y1
5159
          };
5160
        } else {
5161
          if (!va) va = {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5162
            x: (y1 - fb) / fm,
5163
            y: y1
5164
          }; else if (va.y < y0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5165
          vb = {
5166
            x: (y0 - fb) / fm,
5167
            y: y0
5168
          };
5169
        }
5170
      } else {
5171
        if (ly < ry) {
5172
          if (!va) va = {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5173
            x: x0,
5174
            y: fm * x0 + fb
5175
          }; else if (va.x >= x1) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5176
          vb = {
5177
            x: x1,
5178
            y: fm * x1 + fb
5179
          };
5180
        } else {
5181
          if (!va) va = {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5182
            x: x1,
5183
            y: fm * x1 + fb
5184
          }; else if (va.x < x0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5185
          vb = {
5186
            x: x0,
5187
            y: fm * x0 + fb
5188
          };
5189
        }
5190
      }
5191
    }
5192
    edge.a = va;
5193
    edge.b = vb;
5194
    return true;
5195
  }
5196
  function d3_geom_voronoiEdge(lSite, rSite) {
5197
    this.l = lSite;
5198
    this.r = rSite;
5199
    this.a = this.b = null;
5200
  }
5201
  function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
5202
    var edge = new d3_geom_voronoiEdge(lSite, rSite);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiEdge should be capitalized.
Loading history...
5203
    d3_geom_voronoiEdges.push(edge);
5204
    if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5205
    if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5206
    d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiHalfEdge should be capitalized.
Loading history...
5207
    d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiHalfEdge should be capitalized.
Loading history...
5208
    return edge;
5209
  }
5210
  function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
5211
    var edge = new d3_geom_voronoiEdge(lSite, null);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiEdge should be capitalized.
Loading history...
5212
    edge.a = va;
5213
    edge.b = vb;
5214
    d3_geom_voronoiEdges.push(edge);
5215
    return edge;
5216
  }
5217
  function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
5218
    if (!edge.a && !edge.b) {
5219
      edge.a = vertex;
5220
      edge.l = lSite;
5221
      edge.r = rSite;
5222
    } else if (edge.l === rSite) {
5223
      edge.b = vertex;
5224
    } else {
5225
      edge.a = vertex;
5226
    }
5227
  }
5228
  function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
5229
    var va = edge.a, vb = edge.b;
5230
    this.edge = edge;
5231
    this.site = lSite;
5232
    this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
5233
  }
5234
  d3_geom_voronoiHalfEdge.prototype = {
5235
    start: function() {
5236
      return this.edge.l === this.site ? this.edge.a : this.edge.b;
5237
    },
5238
    end: function() {
5239
      return this.edge.l === this.site ? this.edge.b : this.edge.a;
5240
    }
5241
  };
5242
  function d3_geom_voronoiRedBlackTree() {
5243
    this._ = null;
5244
  }
5245
  function d3_geom_voronoiRedBlackNode(node) {
5246
    node.U = node.C = node.L = node.R = node.P = node.N = null;
5247
  }
5248
  d3_geom_voronoiRedBlackTree.prototype = {
5249
    insert: function(after, node) {
5250
      var parent, grandpa, uncle;
5251
      if (after) {
5252
        node.P = after;
5253
        node.N = after.N;
5254
        if (after.N) after.N.P = node;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5255
        after.N = node;
5256
        if (after.R) {
5257
          after = after.R;
5258
          while (after.L) after = after.L;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5259
          after.L = node;
5260
        } else {
5261
          after.R = node;
5262
        }
5263
        parent = after;
5264
      } else if (this._) {
5265
        after = d3_geom_voronoiRedBlackFirst(this._);
5266
        node.P = null;
5267
        node.N = after;
5268
        after.P = after.L = node;
5269
        parent = after;
5270
      } else {
5271
        node.P = node.N = null;
5272
        this._ = node;
5273
        parent = null;
5274
      }
5275
      node.L = node.R = null;
5276
      node.U = parent;
5277
      node.C = true;
5278
      after = node;
5279
      while (parent && parent.C) {
5280
        grandpa = parent.U;
5281
        if (parent === grandpa.L) {
5282
          uncle = grandpa.R;
5283
          if (uncle && uncle.C) {
5284
            parent.C = uncle.C = false;
5285
            grandpa.C = true;
5286
            after = grandpa;
5287
          } else {
5288
            if (after === parent.R) {
5289
              d3_geom_voronoiRedBlackRotateLeft(this, parent);
5290
              after = parent;
5291
              parent = after.U;
5292
            }
5293
            parent.C = false;
5294
            grandpa.C = true;
5295
            d3_geom_voronoiRedBlackRotateRight(this, grandpa);
5296
          }
5297
        } else {
5298
          uncle = grandpa.L;
5299
          if (uncle && uncle.C) {
5300
            parent.C = uncle.C = false;
5301
            grandpa.C = true;
5302
            after = grandpa;
5303
          } else {
5304
            if (after === parent.L) {
5305
              d3_geom_voronoiRedBlackRotateRight(this, parent);
5306
              after = parent;
5307
              parent = after.U;
5308
            }
5309
            parent.C = false;
5310
            grandpa.C = true;
5311
            d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
5312
          }
5313
        }
5314
        parent = after.U;
5315
      }
5316
      this._.C = false;
5317
    },
5318
    remove: function(node) {
5319
      if (node.N) node.N.P = node.P;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5320
      if (node.P) node.P.N = node.N;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5321
      node.N = node.P = null;
5322
      var parent = node.U, sibling, left = node.L, right = node.R, next, red;
5323
      if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5324
      if (parent) {
5325
        if (parent.L === node) parent.L = next; else parent.R = next;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5326
      } else {
5327
        this._ = next;
5328
      }
5329
      if (left && right) {
5330
        red = next.C;
5331
        next.C = node.C;
5332
        next.L = left;
5333
        left.U = next;
5334
        if (next !== right) {
5335
          parent = next.U;
5336
          next.U = node.U;
5337
          node = next.R;
5338
          parent.L = node;
5339
          next.R = right;
5340
          right.U = next;
5341
        } else {
5342
          next.U = parent;
5343
          parent = next;
5344
          node = next.R;
5345
        }
5346
      } else {
5347
        red = node.C;
5348
        node = next;
5349
      }
5350
      if (node) node.U = parent;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5351
      if (red) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5352
      if (node && node.C) {
5353
        node.C = false;
5354
        return;
5355
      }
5356
      do {
5357
        if (node === this._) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5358
        if (node === parent.L) {
5359
          sibling = parent.R;
5360
          if (sibling.C) {
5361
            sibling.C = false;
5362
            parent.C = true;
5363
            d3_geom_voronoiRedBlackRotateLeft(this, parent);
5364
            sibling = parent.R;
5365
          }
5366
          if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5367
            if (!sibling.R || !sibling.R.C) {
5368
              sibling.L.C = false;
5369
              sibling.C = true;
5370
              d3_geom_voronoiRedBlackRotateRight(this, sibling);
5371
              sibling = parent.R;
5372
            }
5373
            sibling.C = parent.C;
5374
            parent.C = sibling.R.C = false;
5375
            d3_geom_voronoiRedBlackRotateLeft(this, parent);
5376
            node = this._;
5377
            break;
5378
          }
5379
        } else {
5380
          sibling = parent.L;
5381
          if (sibling.C) {
5382
            sibling.C = false;
5383
            parent.C = true;
5384
            d3_geom_voronoiRedBlackRotateRight(this, parent);
5385
            sibling = parent.L;
5386
          }
5387
          if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5388
            if (!sibling.L || !sibling.L.C) {
5389
              sibling.R.C = false;
5390
              sibling.C = true;
5391
              d3_geom_voronoiRedBlackRotateLeft(this, sibling);
5392
              sibling = parent.L;
5393
            }
5394
            sibling.C = parent.C;
5395
            parent.C = sibling.L.C = false;
5396
            d3_geom_voronoiRedBlackRotateRight(this, parent);
5397
            node = this._;
5398
            break;
5399
          }
5400
        }
5401
        sibling.C = true;
5402
        node = parent;
5403
        parent = parent.U;
5404
      } while (!node.C);
5405
      if (node) node.C = false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5406
    }
5407
  };
5408
  function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
5409
    var p = node, q = node.R, parent = p.U;
5410
    if (parent) {
5411
      if (parent.L === p) parent.L = q; else parent.R = q;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5412
    } else {
5413
      tree._ = q;
5414
    }
5415
    q.U = parent;
5416
    p.U = q;
5417
    p.R = q.L;
5418
    if (p.R) p.R.U = p;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5419
    q.L = p;
5420
  }
5421
  function d3_geom_voronoiRedBlackRotateRight(tree, node) {
5422
    var p = node, q = node.L, parent = p.U;
5423
    if (parent) {
5424
      if (parent.L === p) parent.L = q; else parent.R = q;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5425
    } else {
5426
      tree._ = q;
5427
    }
5428
    q.U = parent;
5429
    p.U = q;
5430
    p.L = q.R;
5431
    if (p.L) p.L.U = p;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5432
    q.R = p;
5433
  }
5434
  function d3_geom_voronoiRedBlackFirst(node) {
5435
    while (node.L) node = node.L;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5436
    return node;
5437
  }
5438
  function d3_geom_voronoi(sites, bbox) {
5439
    var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
5440
    d3_geom_voronoiEdges = [];
5441
    d3_geom_voronoiCells = new Array(sites.length);
5442
    d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiRedBlackTree should be capitalized.
Loading history...
5443
    d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiRedBlackTree should be capitalized.
Loading history...
5444
    while (true) {
5445
      circle = d3_geom_voronoiFirstCircle;
5446
      if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
5447
        if (site.x !== x0 || site.y !== y0) {
0 ignored issues
show
Bug introduced by
The variable x0 seems to not be initialized for all possible execution paths.
Loading history...
Bug introduced by
The variable y0 seems to not be initialized for all possible execution paths.
Loading history...
5448
          d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_geom_voronoiCell should be capitalized.
Loading history...
5449
          d3_geom_voronoiAddBeach(site);
5450
          x0 = site.x, y0 = site.y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5451
        }
5452
        site = sites.pop();
5453
      } else if (circle) {
5454
        d3_geom_voronoiRemoveBeach(circle.arc);
5455
      } else {
5456
        break;
5457
      }
5458
    }
5459
    if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5460
    var diagram = {
5461
      cells: d3_geom_voronoiCells,
5462
      edges: d3_geom_voronoiEdges
5463
    };
5464
    d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
5465
    return diagram;
5466
  }
5467
  function d3_geom_voronoiVertexOrder(a, b) {
5468
    return b.y - a.y || b.x - a.x;
5469
  }
5470
  d3.geom.voronoi = function(points) {
5471
    var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
5472
    if (points) return voronoi(points);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5473
    function voronoi(data) {
5474
      var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
5475
      d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
5476
        var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
5477
          var s = e.start();
5478
          return [ s.x, s.y ];
5479
        }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
5480
        polygon.point = data[i];
5481
      });
5482
      return polygons;
5483
    }
5484
    function sites(data) {
5485
      return data.map(function(d, i) {
5486
        return {
5487
          x: Math.round(fx(d, i) / ε) * ε,
5488
          y: Math.round(fy(d, i) / ε) * ε,
5489
          i: i
5490
        };
5491
      });
5492
    }
5493
    voronoi.links = function(data) {
5494
      return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
5495
        return edge.l && edge.r;
5496
      }).map(function(edge) {
5497
        return {
5498
          source: data[edge.l.i],
5499
          target: data[edge.r.i]
5500
        };
5501
      });
5502
    };
5503
    voronoi.triangles = function(data) {
5504
      var triangles = [];
5505
      d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
5506
        var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
5507
        while (++j < m) {
5508
          e0 = e1;
0 ignored issues
show
Unused Code introduced by
The variable e0 seems to be never used. Consider removing it.
Loading history...
5509
          s0 = s1;
5510
          e1 = edges[j].edge;
5511
          s1 = e1.l === site ? e1.r : e1.l;
5512
          if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
5513
            triangles.push([ data[i], data[s0.i], data[s1.i] ]);
5514
          }
5515
        }
5516
      });
5517
      return triangles;
5518
    };
5519
    voronoi.x = function(_) {
5520
      return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5521
    };
5522
    voronoi.y = function(_) {
5523
      return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5524
    };
5525
    voronoi.clipExtent = function(_) {
5526
      if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5527
      clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
5528
      return voronoi;
5529
    };
5530
    voronoi.size = function(_) {
5531
      if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5532
      return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
5533
    };
5534
    return voronoi;
5535
  };
5536
  var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
5537
  function d3_geom_voronoiTriangleArea(a, b, c) {
5538
    return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
5539
  }
5540
  d3.geom.delaunay = function(vertices) {
5541
    return d3.geom.voronoi().triangles(vertices);
5542
  };
5543
  d3.geom.quadtree = function(points, x1, y1, x2, y2) {
5544
    var x = d3_geom_pointX, y = d3_geom_pointY, compat;
5545
    if (compat = arguments.length) {
5546
      x = d3_geom_quadtreeCompatX;
5547
      y = d3_geom_quadtreeCompatY;
5548
      if (compat === 3) {
5549
        y2 = y1;
5550
        x2 = x1;
5551
        y1 = x1 = 0;
5552
      }
5553
      return quadtree(points);
5554
    }
5555
    function quadtree(data) {
5556
      var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
5557
      if (x1 != null) {
5558
        x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5559
      } else {
5560
        x2_ = y2_ = -(x1_ = y1_ = Infinity);
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as y1_. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
5561
        xs = [], ys = [];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5562
        n = data.length;
5563
        if (compat) for (i = 0; i < n; ++i) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5564
          d = data[i];
5565
          if (d.x < x1_) x1_ = d.x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5566
          if (d.y < y1_) y1_ = d.y;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5567
          if (d.x > x2_) x2_ = d.x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5568
          if (d.y > y2_) y2_ = d.y;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5569
          xs.push(d.x);
5570
          ys.push(d.y);
5571
        } else for (i = 0; i < n; ++i) {
5572
          var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
5573
          if (x_ < x1_) x1_ = x_;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5574
          if (y_ < y1_) y1_ = y_;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5575
          if (x_ > x2_) x2_ = x_;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5576
          if (y_ > y2_) y2_ = y_;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5577
          xs.push(x_);
5578
          ys.push(y_);
5579
        }
5580
      }
5581
      var dx = x2_ - x1_, dy = y2_ - y1_;
5582
      if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5583
      function insert(n, d, x, y, x1, y1, x2, y2) {
5584
        if (isNaN(x) || isNaN(y)) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5585
        if (n.leaf) {
5586
          var nx = n.x, ny = n.y;
5587
          if (nx != null) {
5588
            if (abs(nx - x) + abs(ny - y) < .01) {
5589
              insertChild(n, d, x, y, x1, y1, x2, y2);
5590
            } else {
5591
              var nPoint = n.point;
5592
              n.x = n.y = n.point = null;
5593
              insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
5594
              insertChild(n, d, x, y, x1, y1, x2, y2);
5595
            }
5596
          } else {
5597
            n.x = x, n.y = y, n.point = d;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5598
          }
5599
        } else {
5600
          insertChild(n, d, x, y, x1, y1, x2, y2);
5601
        }
5602
      }
5603
      function insertChild(n, d, x, y, x1, y1, x2, y2) {
5604
        var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
5605
        n.leaf = false;
5606
        n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
5607
        if (right) x1 = xm; else x2 = xm;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5608
        if (below) y1 = ym; else y2 = ym;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5609
        insert(n, d, x, y, x1, y1, x2, y2);
5610
      }
5611
      var root = d3_geom_quadtreeNode();
5612
      root.add = function(d) {
5613
        insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
0 ignored issues
show
Bug introduced by
The variable i seems to not be initialized for all possible execution paths.
Loading history...
5614
      };
5615
      root.visit = function(f) {
5616
        d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
5617
      };
5618
      root.find = function(point) {
5619
        return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
5620
      };
5621
      i = -1;
5622
      if (x1 == null) {
5623
        while (++i < n) {
0 ignored issues
show
Bug introduced by
The variable n seems to not be initialized for all possible execution paths.
Loading history...
5624
          insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
0 ignored issues
show
Bug introduced by
The variable xs seems to not be initialized for all possible execution paths.
Loading history...
Bug introduced by
The variable ys seems to not be initialized for all possible execution paths.
Loading history...
5625
        }
5626
        --i;
5627
      } else data.forEach(root.add);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5628
      xs = ys = data = d = null;
0 ignored issues
show
Unused Code introduced by
The assignment to variable data seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable ys seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable xs seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to d seems to be never used. If you intend to free memory here, this is not necessary since the variable leaves the scope anyway.
Loading history...
5629
      return root;
5630
    }
5631
    quadtree.x = function(_) {
5632
      return arguments.length ? (x = _, quadtree) : x;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5633
    };
5634
    quadtree.y = function(_) {
5635
      return arguments.length ? (y = _, quadtree) : y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5636
    };
5637
    quadtree.extent = function(_) {
5638
      if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5639
      if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5640
      y2 = +_[1][1];
5641
      return quadtree;
5642
    };
5643
    quadtree.size = function(_) {
5644
      if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5645
      if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5646
      return quadtree;
5647
    };
5648
    return quadtree;
5649
  };
5650
  function d3_geom_quadtreeCompatX(d) {
5651
    return d.x;
5652
  }
5653
  function d3_geom_quadtreeCompatY(d) {
5654
    return d.y;
5655
  }
5656
  function d3_geom_quadtreeNode() {
5657
    return {
5658
      leaf: true,
5659
      nodes: [],
5660
      point: null,
5661
      x: null,
5662
      y: null
5663
    };
5664
  }
5665
  function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
5666
    if (!f(node, x1, y1, x2, y2)) {
5667
      var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
5668
      if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5669
      if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5670
      if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5671
      if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5672
    }
5673
  }
5674
  function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
5675
    var minDistance2 = Infinity, closestPoint;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as minDistance2. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
5676
    (function find(node, x1, y1, x2, y2) {
5677
      if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5678
      if (point = node.point) {
5679
        var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
5680
        if (distance2 < minDistance2) {
5681
          var distance = Math.sqrt(minDistance2 = distance2);
5682
          x0 = x - distance, y0 = y - distance;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5683
          x3 = x + distance, y3 = y + distance;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5684
          closestPoint = point;
5685
        }
5686
      }
5687
      var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
5688
      for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
5689
        if (node = children[i & 3]) switch (i & 3) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5690
         case 0:
5691
          find(node, x1, y1, xm, ym);
5692
          break;
5693
5694
         case 1:
5695
          find(node, xm, y1, x2, ym);
5696
          break;
5697
5698
         case 2:
5699
          find(node, x1, ym, xm, y2);
5700
          break;
5701
5702
         case 3:
5703
          find(node, xm, ym, x2, y2);
5704
          break;
5705
        }
5706
      }
5707
    })(root, x0, y0, x3, y3);
5708
    return closestPoint;
5709
  }
5710
  d3.interpolateRgb = d3_interpolateRgb;
5711
  function d3_interpolateRgb(a, b) {
5712
    a = d3.rgb(a);
5713
    b = d3.rgb(b);
5714
    var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
5715
    return function(t) {
5716
      return "#" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t));
5717
    };
5718
  }
5719
  d3.interpolateObject = d3_interpolateObject;
5720
  function d3_interpolateObject(a, b) {
5721
    var i = {}, c = {}, k;
5722
    for (k in a) {
5723
      if (k in b) {
5724
        i[k] = d3_interpolate(a[k], b[k]);
5725
      } else {
5726
        c[k] = a[k];
5727
      }
5728
    }
5729
    for (k in b) {
5730
      if (!(k in a)) {
5731
        c[k] = b[k];
5732
      }
5733
    }
5734
    return function(t) {
5735
      for (k in i) c[k] = i[k](t);
0 ignored issues
show
introduced by
The variable k is changed by the for-each loop on line 5735. Only the value of the last iteration will be visible in this function if it is called outside of the loop.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5736
      return c;
5737
    };
5738
  }
5739
  d3.interpolateNumber = d3_interpolateNumber;
5740
  function d3_interpolateNumber(a, b) {
5741
    a = +a, b = +b;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5742
    return function(t) {
5743
      return a * (1 - t) + b * t;
5744
    };
5745
  }
5746
  d3.interpolateString = d3_interpolateString;
5747
  function d3_interpolateString(a, b) {
5748
    var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
5749
    a = a + "", b = b + "";
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5750
    while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
5751
      if ((bs = bm.index) > bi) {
5752
        bs = b.slice(bi, bs);
5753
        if (s[i]) s[i] += bs; else s[++i] = bs;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5754
      }
5755
      if ((am = am[0]) === (bm = bm[0])) {
5756
        if (s[i]) s[i] += bm; else s[++i] = bm;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5757
      } else {
5758
        s[++i] = null;
5759
        q.push({
5760
          i: i,
5761
          x: d3_interpolateNumber(am, bm)
5762
        });
5763
      }
5764
      bi = d3_interpolate_numberB.lastIndex;
5765
    }
5766
    if (bi < b.length) {
5767
      bs = b.slice(bi);
5768
      if (s[i]) s[i] += bs; else s[++i] = bs;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5769
    }
5770
    return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5771
      return b(t) + "";
5772
    }) : function() {
5773
      return b;
5774
    } : (b = q.length, function(t) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5775
      for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable o seems to not be initialized for all possible execution paths.
Loading history...
5776
      return s.join("");
5777
    });
5778
  }
5779
  var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
5780
  d3.interpolate = d3_interpolate;
5781
  function d3_interpolate(a, b) {
5782
    var i = d3.interpolators.length, f;
5783
    while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
introduced by
The while loop does not have a body. Maybe you have misplaced a semicolon. If you do wish to have a loop without a body, use an empty body {}.
Loading history...
5784
    return f;
0 ignored issues
show
Bug introduced by
The variable f seems to not be initialized for all possible execution paths.
Loading history...
5785
  }
5786
  d3.interpolators = [ function(a, b) {
5787
    var t = typeof b;
5788
    return (t === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
5789
  } ];
5790
  d3.interpolateArray = d3_interpolateArray;
5791
  function d3_interpolateArray(a, b) {
5792
    var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
5793
    for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5794
    for (;i < na; ++i) c[i] = a[i];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5795
    for (;i < nb; ++i) c[i] = b[i];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5796
    return function(t) {
5797
      for (i = 0; i < n0; ++i) c[i] = x[i](t);
0 ignored issues
show
Bug introduced by
The variable i is changed as part of the for loop for example by ++i on line 5797. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5798
      return c;
5799
    };
5800
  }
5801
  var d3_ease_default = function() {
5802
    return d3_identity;
5803
  };
5804
  var d3_ease = d3.map({
5805
    linear: d3_ease_default,
5806
    poly: d3_ease_poly,
5807
    quad: function() {
5808
      return d3_ease_quad;
5809
    },
5810
    cubic: function() {
5811
      return d3_ease_cubic;
5812
    },
5813
    sin: function() {
5814
      return d3_ease_sin;
5815
    },
5816
    exp: function() {
5817
      return d3_ease_exp;
5818
    },
5819
    circle: function() {
5820
      return d3_ease_circle;
5821
    },
5822
    elastic: d3_ease_elastic,
5823
    back: d3_ease_back,
5824
    bounce: function() {
5825
      return d3_ease_bounce;
5826
    }
5827
  });
5828
  var d3_ease_mode = d3.map({
5829
    "in": d3_identity,
5830
    out: d3_ease_reverse,
5831
    "in-out": d3_ease_reflect,
5832
    "out-in": function(f) {
5833
      return d3_ease_reflect(d3_ease_reverse(f));
5834
    }
5835
  });
5836
  d3.ease = function(name) {
5837
    var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
5838
    t = d3_ease.get(t) || d3_ease_default;
5839
    m = d3_ease_mode.get(m) || d3_identity;
5840
    return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
5841
  };
5842
  function d3_ease_clamp(f) {
5843
    return function(t) {
5844
      return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
5845
    };
5846
  }
5847
  function d3_ease_reverse(f) {
5848
    return function(t) {
5849
      return 1 - f(1 - t);
5850
    };
5851
  }
5852
  function d3_ease_reflect(f) {
5853
    return function(t) {
5854
      return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
5855
    };
5856
  }
5857
  function d3_ease_quad(t) {
5858
    return t * t;
5859
  }
5860
  function d3_ease_cubic(t) {
5861
    return t * t * t;
5862
  }
5863
  function d3_ease_cubicInOut(t) {
5864
    if (t <= 0) return 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5865
    if (t >= 1) return 1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5866
    var t2 = t * t, t3 = t2 * t;
5867
    return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
5868
  }
5869
  function d3_ease_poly(e) {
5870
    return function(t) {
5871
      return Math.pow(t, e);
5872
    };
5873
  }
5874
  function d3_ease_sin(t) {
5875
    return 1 - Math.cos(t * halfπ);
5876
  }
5877
  function d3_ease_exp(t) {
5878
    return Math.pow(2, 10 * (t - 1));
5879
  }
5880
  function d3_ease_circle(t) {
5881
    return 1 - Math.sqrt(1 - t * t);
5882
  }
5883
  function d3_ease_elastic(a, p) {
5884
    var s;
5885
    if (arguments.length < 2) p = .45;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5886
    if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5887
    return function(t) {
5888
      return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
5889
    };
5890
  }
5891
  function d3_ease_back(s) {
5892
    if (!s) s = 1.70158;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5893
    return function(t) {
5894
      return t * t * ((s + 1) * t - s);
5895
    };
5896
  }
5897
  function d3_ease_bounce(t) {
5898
    return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375;
5899
  }
5900
  d3.interpolateHcl = d3_interpolateHcl;
5901
  function d3_interpolateHcl(a, b) {
5902
    a = d3.hcl(a);
5903
    b = d3.hcl(b);
5904
    var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
5905
    if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
5906
    if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5907
    return function(t) {
5908
      return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
5909
    };
5910
  }
5911
  d3.interpolateHsl = d3_interpolateHsl;
5912
  function d3_interpolateHsl(a, b) {
5913
    a = d3.hsl(a);
5914
    b = d3.hsl(b);
5915
    var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
5916
    if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5917
    if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
5918
    return function(t) {
5919
      return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
5920
    };
5921
  }
5922
  d3.interpolateLab = d3_interpolateLab;
5923
  function d3_interpolateLab(a, b) {
5924
    a = d3.lab(a);
5925
    b = d3.lab(b);
5926
    var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
5927
    return function(t) {
5928
      return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
5929
    };
5930
  }
5931
  d3.interpolateRound = d3_interpolateRound;
5932
  function d3_interpolateRound(a, b) {
5933
    b -= a;
5934
    return function(t) {
5935
      return Math.round(a + b * t);
5936
    };
5937
  }
5938
  d3.transform = function(string) {
5939
    var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
5940
    return (d3.transform = function(string) {
5941
      if (string != null) {
5942
        g.setAttribute("transform", string);
5943
        var t = g.transform.baseVal.consolidate();
5944
      }
5945
      return new d3_transform(t ? t.matrix : d3_transformIdentity);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_transform should be capitalized.
Loading history...
5946
    })(string);
5947
  };
5948
  function d3_transform(m) {
5949
    var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;
5950
    if (r0[0] * r1[1] < r1[0] * r0[1]) {
5951
      r0[0] *= -1;
5952
      r0[1] *= -1;
5953
      kx *= -1;
5954
      kz *= -1;
5955
    }
5956
    this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
5957
    this.translate = [ m.e, m.f ];
5958
    this.scale = [ kx, ky ];
5959
    this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
5960
  }
5961
  d3_transform.prototype.toString = function() {
5962
    return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
5963
  };
5964
  function d3_transformDot(a, b) {
5965
    return a[0] * b[0] + a[1] * b[1];
5966
  }
5967
  function d3_transformNormalize(a) {
5968
    var k = Math.sqrt(d3_transformDot(a, a));
5969
    if (k) {
5970
      a[0] /= k;
5971
      a[1] /= k;
5972
    }
5973
    return k;
5974
  }
5975
  function d3_transformCombine(a, b, k) {
5976
    a[0] += k * b[0];
5977
    a[1] += k * b[1];
5978
    return a;
5979
  }
5980
  var d3_transformIdentity = {
5981
    a: 1,
5982
    b: 0,
5983
    c: 0,
5984
    d: 1,
5985
    e: 0,
5986
    f: 0
5987
  };
5988
  d3.interpolateTransform = d3_interpolateTransform;
5989
  function d3_interpolateTransform(a, b) {
5990
    var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
5991
    if (ta[0] != tb[0] || ta[1] != tb[1]) {
5992
      s.push("translate(", null, ",", null, ")");
5993
      q.push({
5994
        i: 1,
5995
        x: d3_interpolateNumber(ta[0], tb[0])
5996
      }, {
5997
        i: 3,
5998
        x: d3_interpolateNumber(ta[1], tb[1])
5999
      });
6000
    } else if (tb[0] || tb[1]) {
6001
      s.push("translate(" + tb + ")");
6002
    } else {
6003
      s.push("");
6004
    }
6005
    if (ra != rb) {
6006
      if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6007
      q.push({
6008
        i: s.push(s.pop() + "rotate(", null, ")") - 2,
6009
        x: d3_interpolateNumber(ra, rb)
6010
      });
6011
    } else if (rb) {
6012
      s.push(s.pop() + "rotate(" + rb + ")");
6013
    }
6014
    if (wa != wb) {
6015
      q.push({
6016
        i: s.push(s.pop() + "skewX(", null, ")") - 2,
6017
        x: d3_interpolateNumber(wa, wb)
6018
      });
6019
    } else if (wb) {
6020
      s.push(s.pop() + "skewX(" + wb + ")");
6021
    }
6022
    if (ka[0] != kb[0] || ka[1] != kb[1]) {
6023
      n = s.push(s.pop() + "scale(", null, ",", null, ")");
6024
      q.push({
6025
        i: n - 4,
6026
        x: d3_interpolateNumber(ka[0], kb[0])
6027
      }, {
6028
        i: n - 2,
6029
        x: d3_interpolateNumber(ka[1], kb[1])
6030
      });
6031
    } else if (kb[0] != 1 || kb[1] != 1) {
6032
      s.push(s.pop() + "scale(" + kb + ")");
6033
    }
6034
    n = q.length;
6035
    return function(t) {
6036
      var i = -1, o;
6037
      while (++i < n) s[(o = q[i]).i] = o.x(t);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable o seems to not be initialized for all possible execution paths.
Loading history...
6038
      return s.join("");
6039
    };
6040
  }
6041
  function d3_uninterpolateNumber(a, b) {
6042
    b = (b -= a = +a) || 1 / b;
6043
    return function(x) {
6044
      return (x - a) / b;
6045
    };
6046
  }
6047
  function d3_uninterpolateClamp(a, b) {
6048
    b = (b -= a = +a) || 1 / b;
6049
    return function(x) {
6050
      return Math.max(0, Math.min(1, (x - a) / b));
6051
    };
6052
  }
6053
  d3.layout = {};
6054
  d3.layout.bundle = function() {
6055
    return function(links) {
6056
      var paths = [], i = -1, n = links.length;
6057
      while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6058
      return paths;
6059
    };
6060
  };
6061
  function d3_layout_bundlePath(link) {
6062
    var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
6063
    while (start !== lca) {
6064
      start = start.parent;
6065
      points.push(start);
6066
    }
6067
    var k = points.length;
6068
    while (end !== lca) {
6069
      points.splice(k, 0, end);
6070
      end = end.parent;
6071
    }
6072
    return points;
6073
  }
6074
  function d3_layout_bundleAncestors(node) {
6075
    var ancestors = [], parent = node.parent;
6076
    while (parent != null) {
6077
      ancestors.push(node);
6078
      node = parent;
6079
      parent = parent.parent;
6080
    }
6081
    ancestors.push(node);
6082
    return ancestors;
6083
  }
6084
  function d3_layout_bundleLeastCommonAncestor(a, b) {
6085
    if (a === b) return a;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6086
    var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
6087
    while (aNode === bNode) {
6088
      sharedNode = aNode;
6089
      aNode = aNodes.pop();
6090
      bNode = bNodes.pop();
6091
    }
6092
    return sharedNode;
6093
  }
6094
  d3.layout.chord = function() {
6095
    var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
6096
    function relayout() {
6097
      var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
6098
      chords = [];
6099
      groups = [];
6100
      k = 0, i = -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
6101
      while (++i < n) {
6102
        x = 0, j = -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
6103
        while (++j < n) {
6104
          x += matrix[i][j];
6105
        }
6106
        groupSums.push(x);
6107
        subgroupIndex.push(d3.range(n));
6108
        k += x;
6109
      }
6110
      if (sortGroups) {
6111
        groupIndex.sort(function(a, b) {
6112
          return sortGroups(groupSums[a], groupSums[b]);
6113
        });
6114
      }
6115
      if (sortSubgroups) {
6116
        subgroupIndex.forEach(function(d, i) {
6117
          d.sort(function(a, b) {
6118
            return sortSubgroups(matrix[i][a], matrix[i][b]);
6119
          });
6120
        });
6121
      }
6122
      k = (τ - padding * n) / k;
6123
      x = 0, i = -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
6124
      while (++i < n) {
6125
        x0 = x, j = -1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
6126
        while (++j < n) {
6127
          var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
6128
          subgroups[di + "-" + dj] = {
6129
            index: di,
6130
            subindex: dj,
6131
            startAngle: a0,
6132
            endAngle: a1,
6133
            value: v
6134
          };
6135
        }
6136
        groups[di] = {
0 ignored issues
show
Bug introduced by
The variable di seems to not be initialized for all possible execution paths.
Loading history...
6137
          index: di,
6138
          startAngle: x0,
6139
          endAngle: x,
6140
          value: (x - x0) / k
6141
        };
6142
        x += padding;
6143
      }
6144
      i = -1;
6145
      while (++i < n) {
6146
        j = i - 1;
6147
        while (++j < n) {
6148
          var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
6149
          if (source.value || target.value) {
6150
            chords.push(source.value < target.value ? {
6151
              source: target,
6152
              target: source
6153
            } : {
6154
              source: source,
6155
              target: target
6156
            });
6157
          }
6158
        }
6159
      }
6160
      if (sortChords) resort();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6161
    }
6162
    function resort() {
6163
      chords.sort(function(a, b) {
6164
        return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
6165
      });
6166
    }
6167
    chord.matrix = function(x) {
6168
      if (!arguments.length) return matrix;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6169
      n = (matrix = x) && matrix.length;
6170
      chords = groups = null;
6171
      return chord;
6172
    };
6173
    chord.padding = function(x) {
6174
      if (!arguments.length) return padding;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6175
      padding = x;
6176
      chords = groups = null;
6177
      return chord;
6178
    };
6179
    chord.sortGroups = function(x) {
6180
      if (!arguments.length) return sortGroups;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6181
      sortGroups = x;
6182
      chords = groups = null;
6183
      return chord;
6184
    };
6185
    chord.sortSubgroups = function(x) {
6186
      if (!arguments.length) return sortSubgroups;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6187
      sortSubgroups = x;
6188
      chords = null;
6189
      return chord;
6190
    };
6191
    chord.sortChords = function(x) {
6192
      if (!arguments.length) return sortChords;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6193
      sortChords = x;
6194
      if (chords) resort();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6195
      return chord;
6196
    };
6197
    chord.chords = function() {
6198
      if (!chords) relayout();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6199
      return chords;
0 ignored issues
show
Bug introduced by
The variable chords seems to not be initialized for all possible execution paths.
Loading history...
6200
    };
6201
    chord.groups = function() {
6202
      if (!groups) relayout();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6203
      return groups;
0 ignored issues
show
Bug introduced by
The variable groups seems to not be initialized for all possible execution paths.
Loading history...
6204
    };
6205
    return chord;
6206
  };
6207
  d3.layout.force = function() {
6208
    var force = {}, event = d3.dispatch("start", "tick", "end"), size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
6209
    function repulse(node) {
6210
      return function(quad, x1, _, x2) {
6211
        if (quad.point !== node) {
6212
          var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
6213
          if (dw * dw / theta2 < dn) {
6214
            if (dn < chargeDistance2) {
6215
              var k = quad.charge / dn;
6216
              node.px -= dx * k;
6217
              node.py -= dy * k;
6218
            }
6219
            return true;
6220
          }
6221
          if (quad.point && dn && dn < chargeDistance2) {
6222
            var k = quad.pointCharge / dn;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable k already seems to be declared on line 6215. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
6223
            node.px -= dx * k;
6224
            node.py -= dy * k;
6225
          }
6226
        }
6227
        return !quad.charge;
6228
      };
6229
    }
6230
    force.tick = function() {
6231
      if ((alpha *= .99) < .005) {
6232
        event.end({
6233
          type: "end",
6234
          alpha: alpha = 0
6235
        });
6236
        return true;
6237
      }
6238
      var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
6239
      for (i = 0; i < m; ++i) {
6240
        o = links[i];
6241
        s = o.source;
6242
        t = o.target;
6243
        x = t.x - s.x;
6244
        y = t.y - s.y;
6245
        if (l = x * x + y * y) {
6246
          l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
6247
          x *= l;
6248
          y *= l;
6249
          t.x -= x * (k = s.weight / (t.weight + s.weight));
6250
          t.y -= y * k;
6251
          s.x += x * (k = 1 - k);
6252
          s.y += y * k;
6253
        }
6254
      }
6255
      if (k = alpha * gravity) {
6256
        x = size[0] / 2;
6257
        y = size[1] / 2;
6258
        i = -1;
6259
        if (k) while (++i < n) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6260
          o = nodes[i];
6261
          o.x += (x - o.x) * k;
6262
          o.y += (y - o.y) * k;
6263
        }
6264
      }
6265
      if (charge) {
6266
        d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
6267
        i = -1;
6268
        while (++i < n) {
6269
          if (!(o = nodes[i]).fixed) {
6270
            q.visit(repulse(o));
6271
          }
6272
        }
6273
      }
6274
      i = -1;
6275
      while (++i < n) {
6276
        o = nodes[i];
6277
        if (o.fixed) {
6278
          o.x = o.px;
6279
          o.y = o.py;
6280
        } else {
6281
          o.x -= (o.px - (o.px = o.x)) * friction;
6282
          o.y -= (o.py - (o.py = o.y)) * friction;
6283
        }
6284
      }
6285
      event.tick({
6286
        type: "tick",
6287
        alpha: alpha
6288
      });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
6289
    };
6290
    force.nodes = function(x) {
6291
      if (!arguments.length) return nodes;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6292
      nodes = x;
6293
      return force;
6294
    };
6295
    force.links = function(x) {
6296
      if (!arguments.length) return links;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6297
      links = x;
6298
      return force;
6299
    };
6300
    force.size = function(x) {
6301
      if (!arguments.length) return size;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6302
      size = x;
6303
      return force;
6304
    };
6305
    force.linkDistance = function(x) {
6306
      if (!arguments.length) return linkDistance;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6307
      linkDistance = typeof x === "function" ? x : +x;
6308
      return force;
6309
    };
6310
    force.distance = force.linkDistance;
6311
    force.linkStrength = function(x) {
6312
      if (!arguments.length) return linkStrength;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6313
      linkStrength = typeof x === "function" ? x : +x;
6314
      return force;
6315
    };
6316
    force.friction = function(x) {
6317
      if (!arguments.length) return friction;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6318
      friction = +x;
6319
      return force;
6320
    };
6321
    force.charge = function(x) {
6322
      if (!arguments.length) return charge;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6323
      charge = typeof x === "function" ? x : +x;
6324
      return force;
6325
    };
6326
    force.chargeDistance = function(x) {
6327
      if (!arguments.length) return Math.sqrt(chargeDistance2);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6328
      chargeDistance2 = x * x;
6329
      return force;
6330
    };
6331
    force.gravity = function(x) {
6332
      if (!arguments.length) return gravity;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6333
      gravity = +x;
6334
      return force;
6335
    };
6336
    force.theta = function(x) {
6337
      if (!arguments.length) return Math.sqrt(theta2);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6338
      theta2 = x * x;
6339
      return force;
6340
    };
6341
    force.alpha = function(x) {
6342
      if (!arguments.length) return alpha;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6343
      x = +x;
6344
      if (alpha) {
6345
        if (x > 0) alpha = x; else alpha = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6346
      } else if (x > 0) {
6347
        event.start({
6348
          type: "start",
6349
          alpha: alpha = x
6350
        });
6351
        d3.timer(force.tick);
6352
      }
6353
      return force;
6354
    };
6355
    force.start = function() {
6356
      var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
6357
      for (i = 0; i < n; ++i) {
6358
        (o = nodes[i]).index = i;
6359
        o.weight = 0;
6360
      }
6361
      for (i = 0; i < m; ++i) {
6362
        o = links[i];
6363
        if (typeof o.source == "number") o.source = nodes[o.source];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6364
        if (typeof o.target == "number") o.target = nodes[o.target];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6365
        ++o.source.weight;
6366
        ++o.target.weight;
6367
      }
6368
      for (i = 0; i < n; ++i) {
6369
        o = nodes[i];
6370
        if (isNaN(o.x)) o.x = position("x", w);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6371
        if (isNaN(o.y)) o.y = position("y", h);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6372
        if (isNaN(o.px)) o.px = o.x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6373
        if (isNaN(o.py)) o.py = o.y;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6374
      }
6375
      distances = [];
6376
      if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6377
      strengths = [];
6378
      if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6379
      charges = [];
6380
      if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6381
      function position(dimension, size) {
6382
        if (!neighbors) {
6383
          neighbors = new Array(n);
6384
          for (j = 0; j < n; ++j) {
6385
            neighbors[j] = [];
6386
          }
6387
          for (j = 0; j < m; ++j) {
6388
            var o = links[j];
6389
            neighbors[o.source.index].push(o.target);
6390
            neighbors[o.target.index].push(o.source);
6391
          }
6392
        }
6393
        var candidates = neighbors[i], j = -1, l = candidates.length, x;
6394
        while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6395
        return Math.random() * size;
6396
      }
6397
      return force.resume();
6398
    };
6399
    force.resume = function() {
6400
      return force.alpha(.1);
6401
    };
6402
    force.stop = function() {
6403
      return force.alpha(0);
6404
    };
6405
    force.drag = function() {
6406
      if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart.force", d3_layout_forceDragstart).on("drag.force", dragmove).on("dragend.force", d3_layout_forceDragend);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6407
      if (!arguments.length) return drag;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6408
      this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
6409
    };
6410
    function dragmove(d) {
6411
      d.px = d3.event.x, d.py = d3.event.y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
6412
      force.resume();
6413
    }
6414
    return d3.rebind(force, event, "on");
6415
  };
6416
  function d3_layout_forceDragstart(d) {
6417
    d.fixed |= 2;
6418
  }
6419
  function d3_layout_forceDragend(d) {
6420
    d.fixed &= ~6;
6421
  }
6422
  function d3_layout_forceMouseover(d) {
6423
    d.fixed |= 4;
6424
    d.px = d.x, d.py = d.y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
6425
  }
6426
  function d3_layout_forceMouseout(d) {
6427
    d.fixed &= ~4;
6428
  }
6429
  function d3_layout_forceAccumulate(quad, alpha, charges) {
6430
    var cx = 0, cy = 0;
6431
    quad.charge = 0;
6432
    if (!quad.leaf) {
6433
      var nodes = quad.nodes, n = nodes.length, i = -1, c;
6434
      while (++i < n) {
6435
        c = nodes[i];
6436
        if (c == null) continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6437
        d3_layout_forceAccumulate(c, alpha, charges);
6438
        quad.charge += c.charge;
6439
        cx += c.charge * c.cx;
6440
        cy += c.charge * c.cy;
6441
      }
6442
    }
6443
    if (quad.point) {
6444
      if (!quad.leaf) {
6445
        quad.point.x += Math.random() - .5;
6446
        quad.point.y += Math.random() - .5;
6447
      }
6448
      var k = alpha * charges[quad.point.index];
6449
      quad.charge += quad.pointCharge = k;
6450
      cx += k * quad.point.x;
6451
      cy += k * quad.point.y;
6452
    }
6453
    quad.cx = cx / quad.charge;
6454
    quad.cy = cy / quad.charge;
6455
  }
6456
  var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as d3_layout_forceChargeDistance2. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
6457
  d3.layout.hierarchy = function() {
6458
    var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
6459
    function hierarchy(root) {
6460
      var stack = [ root ], nodes = [], node;
6461
      root.depth = 0;
6462
      while ((node = stack.pop()) != null) {
6463
        nodes.push(node);
6464
        if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
6465
          var n, childs, child;
6466
          while (--n >= 0) {
6467
            stack.push(child = childs[n]);
6468
            child.parent = node;
6469
            child.depth = node.depth + 1;
6470
          }
6471
          if (value) node.value = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6472
          node.children = childs;
6473
        } else {
6474
          if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6475
          delete node.children;
6476
        }
6477
      }
6478
      d3_layout_hierarchyVisitAfter(root, function(node) {
6479
        var childs, parent;
6480
        if (sort && (childs = node.children)) childs.sort(sort);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6481
        if (value && (parent = node.parent)) parent.value += node.value;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6482
      });
6483
      return nodes;
6484
    }
6485
    hierarchy.sort = function(x) {
6486
      if (!arguments.length) return sort;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6487
      sort = x;
6488
      return hierarchy;
6489
    };
6490
    hierarchy.children = function(x) {
6491
      if (!arguments.length) return children;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6492
      children = x;
6493
      return hierarchy;
6494
    };
6495
    hierarchy.value = function(x) {
6496
      if (!arguments.length) return value;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6497
      value = x;
6498
      return hierarchy;
6499
    };
6500
    hierarchy.revalue = function(root) {
6501
      if (value) {
6502
        d3_layout_hierarchyVisitBefore(root, function(node) {
6503
          if (node.children) node.value = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6504
        });
6505
        d3_layout_hierarchyVisitAfter(root, function(node) {
6506
          var parent;
6507
          if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6508
          if (parent = node.parent) parent.value += node.value;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6509
        });
6510
      }
6511
      return root;
6512
    };
6513
    return hierarchy;
6514
  };
6515
  function d3_layout_hierarchyRebind(object, hierarchy) {
6516
    d3.rebind(object, hierarchy, "sort", "children", "value");
6517
    object.nodes = object;
6518
    object.links = d3_layout_hierarchyLinks;
6519
    return object;
6520
  }
6521
  function d3_layout_hierarchyVisitBefore(node, callback) {
6522
    var nodes = [ node ];
6523
    while ((node = nodes.pop()) != null) {
6524
      callback(node);
6525
      if ((children = node.children) && (n = children.length)) {
6526
        var n, children;
6527
        while (--n >= 0) nodes.push(children[n]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6528
      }
6529
    }
6530
  }
6531
  function d3_layout_hierarchyVisitAfter(node, callback) {
6532
    var nodes = [ node ], nodes2 = [];
6533
    while ((node = nodes.pop()) != null) {
6534
      nodes2.push(node);
6535
      if ((children = node.children) && (n = children.length)) {
6536
        var i = -1, n, children;
6537
        while (++i < n) nodes.push(children[i]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6538
      }
6539
    }
6540
    while ((node = nodes2.pop()) != null) {
6541
      callback(node);
6542
    }
6543
  }
6544
  function d3_layout_hierarchyChildren(d) {
6545
    return d.children;
6546
  }
6547
  function d3_layout_hierarchyValue(d) {
6548
    return d.value;
6549
  }
6550
  function d3_layout_hierarchySort(a, b) {
6551
    return b.value - a.value;
6552
  }
6553
  function d3_layout_hierarchyLinks(nodes) {
6554
    return d3.merge(nodes.map(function(parent) {
6555
      return (parent.children || []).map(function(child) {
6556
        return {
6557
          source: parent,
6558
          target: child
6559
        };
6560
      });
6561
    }));
6562
  }
6563
  d3.layout.partition = function() {
6564
    var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
6565
    function position(node, x, dx, dy) {
6566
      var children = node.children;
6567
      node.x = x;
6568
      node.y = node.depth * dy;
6569
      node.dx = dx;
6570
      node.dy = dy;
6571
      if (children && (n = children.length)) {
6572
        var i = -1, n, c, d;
6573
        dx = node.value ? dx / node.value : 0;
6574
        while (++i < n) {
6575
          position(c = children[i], x, d = c.value * dx, dy);
6576
          x += d;
6577
        }
6578
      }
6579
    }
6580
    function depth(node) {
6581
      var children = node.children, d = 0;
6582
      if (children && (n = children.length)) {
6583
        var i = -1, n;
6584
        while (++i < n) d = Math.max(d, depth(children[i]));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6585
      }
6586
      return 1 + d;
6587
    }
6588
    function partition(d, i) {
6589
      var nodes = hierarchy.call(this, d, i);
6590
      position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
6591
      return nodes;
6592
    }
6593
    partition.size = function(x) {
6594
      if (!arguments.length) return size;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6595
      size = x;
6596
      return partition;
6597
    };
6598
    return d3_layout_hierarchyRebind(partition, hierarchy);
6599
  };
6600
  d3.layout.pie = function() {
6601
    var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Number as value. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
6602
    function pie(data) {
6603
      var n = data.length, values = data.map(function(d, i) {
6604
        return +value.call(pie, d, i);
6605
      }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), k = (da - n * pa) / d3.sum(values), index = d3.range(n), arcs = [], v;
6606
      if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6607
        return values[j] - values[i];
6608
      } : function(i, j) {
6609
        return sort(data[i], data[j]);
6610
      });
6611
      index.forEach(function(i) {
6612
        arcs[i] = {
6613
          data: data[i],
6614
          value: v = values[i],
6615
          startAngle: a,
6616
          endAngle: a += v * k + pa,
6617
          padAngle: p
6618
        };
6619
      });
6620
      return arcs;
6621
    }
6622
    pie.value = function(_) {
6623
      if (!arguments.length) return value;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6624
      value = _;
6625
      return pie;
6626
    };
6627
    pie.sort = function(_) {
6628
      if (!arguments.length) return sort;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6629
      sort = _;
6630
      return pie;
6631
    };
6632
    pie.startAngle = function(_) {
6633
      if (!arguments.length) return startAngle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6634
      startAngle = _;
6635
      return pie;
6636
    };
6637
    pie.endAngle = function(_) {
6638
      if (!arguments.length) return endAngle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6639
      endAngle = _;
6640
      return pie;
6641
    };
6642
    pie.padAngle = function(_) {
6643
      if (!arguments.length) return padAngle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6644
      padAngle = _;
6645
      return pie;
6646
    };
6647
    return pie;
6648
  };
6649
  var d3_layout_pieSortByValue = {};
6650
  d3.layout.stack = function() {
6651
    var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
6652
    function stack(data, index) {
6653
      if (!(n = data.length)) return data;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6654
      var series = data.map(function(d, i) {
6655
        return values.call(stack, d, i);
6656
      });
6657
      var points = series.map(function(d) {
6658
        return d.map(function(v, i) {
6659
          return [ x.call(stack, v, i), y.call(stack, v, i) ];
6660
        });
6661
      });
6662
      var orders = order.call(stack, points, index);
6663
      series = d3.permute(series, orders);
6664
      points = d3.permute(points, orders);
6665
      var offsets = offset.call(stack, points, index);
6666
      var m = series[0].length, n, i, j, o;
6667
      for (j = 0; j < m; ++j) {
6668
        out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
6669
        for (i = 1; i < n; ++i) {
6670
          out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
6671
        }
6672
      }
6673
      return data;
6674
    }
6675
    stack.values = function(x) {
6676
      if (!arguments.length) return values;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6677
      values = x;
6678
      return stack;
6679
    };
6680
    stack.order = function(x) {
6681
      if (!arguments.length) return order;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6682
      order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
6683
      return stack;
6684
    };
6685
    stack.offset = function(x) {
6686
      if (!arguments.length) return offset;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6687
      offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
6688
      return stack;
6689
    };
6690
    stack.x = function(z) {
6691
      if (!arguments.length) return x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6692
      x = z;
6693
      return stack;
6694
    };
6695
    stack.y = function(z) {
6696
      if (!arguments.length) return y;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6697
      y = z;
6698
      return stack;
6699
    };
6700
    stack.out = function(z) {
6701
      if (!arguments.length) return out;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6702
      out = z;
6703
      return stack;
6704
    };
6705
    return stack;
6706
  };
6707
  function d3_layout_stackX(d) {
6708
    return d.x;
6709
  }
6710
  function d3_layout_stackY(d) {
6711
    return d.y;
6712
  }
6713
  function d3_layout_stackOut(d, y0, y) {
6714
    d.y0 = y0;
6715
    d.y = y;
6716
  }
6717
  var d3_layout_stackOrders = d3.map({
6718
    "inside-out": function(data) {
6719
      var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) {
6720
        return max[a] - max[b];
6721
      }), top = 0, bottom = 0, tops = [], bottoms = [];
6722
      for (i = 0; i < n; ++i) {
6723
        j = index[i];
6724
        if (top < bottom) {
6725
          top += sums[j];
6726
          tops.push(j);
6727
        } else {
6728
          bottom += sums[j];
6729
          bottoms.push(j);
6730
        }
6731
      }
6732
      return bottoms.reverse().concat(tops);
6733
    },
6734
    reverse: function(data) {
6735
      return d3.range(data.length).reverse();
6736
    },
6737
    "default": d3_layout_stackOrderDefault
6738
  });
6739
  var d3_layout_stackOffsets = d3.map({
6740 View Code Duplication
    silhouette: function(data) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6741
      var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
6742
      for (j = 0; j < m; ++j) {
6743
        for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6744
        if (o > max) max = o;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6745
        sums.push(o);
6746
      }
6747
      for (j = 0; j < m; ++j) {
6748
        y0[j] = (max - sums[j]) / 2;
6749
      }
6750
      return y0;
6751
    },
6752
    wiggle: function(data) {
6753
      var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
6754
      y0[0] = o = o0 = 0;
6755
      for (j = 1; j < m; ++j) {
6756
        for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6757
        for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
6758
          for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
6759
            s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
6760
          }
6761
          s2 += s3 * data[i][j][1];
6762
        }
6763
        y0[j] = o -= s1 ? s2 / s1 * dx : 0;
6764
        if (o < o0) o0 = o;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6765
      }
6766
      for (j = 0; j < m; ++j) y0[j] -= o0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6767
      return y0;
6768
    },
6769 View Code Duplication
    expand: function(data) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6770
      var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
6771
      for (j = 0; j < m; ++j) {
6772
        for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6773
        if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6774
      }
6775
      for (j = 0; j < m; ++j) y0[j] = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6776
      return y0;
6777
    },
6778
    zero: d3_layout_stackOffsetZero
6779
  });
6780
  function d3_layout_stackOrderDefault(data) {
6781
    return d3.range(data.length);
6782
  }
6783
  function d3_layout_stackOffsetZero(data) {
6784
    var j = -1, m = data[0].length, y0 = [];
6785
    while (++j < m) y0[j] = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6786
    return y0;
6787
  }
6788
  function d3_layout_stackMaxIndex(array) {
6789
    var i = 1, j = 0, v = array[0][1], k, n = array.length;
6790
    for (;i < n; ++i) {
6791
      if ((k = array[i][1]) > v) {
6792
        j = i;
6793
        v = k;
6794
      }
6795
    }
6796
    return j;
6797
  }
6798
  function d3_layout_stackReduceSum(d) {
6799
    return d.reduce(d3_layout_stackSum, 0);
6800
  }
6801
  function d3_layout_stackSum(p, d) {
6802
    return p + d[1];
6803
  }
6804
  d3.layout.histogram = function() {
6805
    var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Number as valuer. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
6806
    function histogram(data, i) {
6807
      var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x;
6808
      while (++i < m) {
6809
        bin = bins[i] = [];
6810
        bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
6811
        bin.y = 0;
6812
      }
6813
      if (m > 0) {
6814
        i = -1;
6815
        while (++i < n) {
6816
          x = values[i];
6817
          if (x >= range[0] && x <= range[1]) {
6818
            bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
6819
            bin.y += k;
6820
            bin.push(data[i]);
6821
          }
6822
        }
6823
      }
6824
      return bins;
6825
    }
6826
    histogram.value = function(x) {
6827
      if (!arguments.length) return valuer;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6828
      valuer = x;
6829
      return histogram;
6830
    };
6831
    histogram.range = function(x) {
6832
      if (!arguments.length) return ranger;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6833
      ranger = d3_functor(x);
6834
      return histogram;
6835
    };
6836
    histogram.bins = function(x) {
6837
      if (!arguments.length) return binner;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6838
      binner = typeof x === "number" ? function(range) {
6839
        return d3_layout_histogramBinFixed(range, x);
6840
      } : d3_functor(x);
6841
      return histogram;
6842
    };
6843
    histogram.frequency = function(x) {
6844
      if (!arguments.length) return frequency;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6845
      frequency = !!x;
6846
      return histogram;
6847
    };
6848
    return histogram;
6849
  };
6850
  function d3_layout_histogramBinSturges(range, values) {
6851
    return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
6852
  }
6853
  function d3_layout_histogramBinFixed(range, n) {
6854
    var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
6855
    while (++x <= n) f[x] = m * x + b;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6856
    return f;
6857
  }
6858
  function d3_layout_histogramRange(values) {
6859
    return [ d3.min(values), d3.max(values) ];
6860
  }
6861
  d3.layout.pack = function() {
6862
    var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
6863
    function pack(d, i) {
6864
      var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() {
6865
        return radius;
6866
      };
6867
      root.x = root.y = 0;
6868
      d3_layout_hierarchyVisitAfter(root, function(d) {
6869
        d.r = +r(d.value);
6870
      });
6871
      d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6872
      if (padding) {
6873
        var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
6874
        d3_layout_hierarchyVisitAfter(root, function(d) {
6875
          d.r += dr;
6876
        });
6877
        d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6878
        d3_layout_hierarchyVisitAfter(root, function(d) {
6879
          d.r -= dr;
6880
        });
6881
      }
6882
      d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
6883
      return nodes;
6884
    }
6885
    pack.size = function(_) {
6886
      if (!arguments.length) return size;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6887
      size = _;
6888
      return pack;
6889
    };
6890
    pack.radius = function(_) {
6891
      if (!arguments.length) return radius;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6892
      radius = _ == null || typeof _ === "function" ? _ : +_;
6893
      return pack;
6894
    };
6895
    pack.padding = function(_) {
6896
      if (!arguments.length) return padding;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6897
      padding = +_;
6898
      return pack;
6899
    };
6900
    return d3_layout_hierarchyRebind(pack, hierarchy);
6901
  };
6902
  function d3_layout_packSort(a, b) {
6903
    return a.value - b.value;
6904
  }
6905
  function d3_layout_packInsert(a, b) {
6906
    var c = a._pack_next;
6907
    a._pack_next = b;
6908
    b._pack_prev = a;
6909
    b._pack_next = c;
6910
    c._pack_prev = b;
6911
  }
6912
  function d3_layout_packSplice(a, b) {
6913
    a._pack_next = b;
6914
    b._pack_prev = a;
6915
  }
6916
  function d3_layout_packIntersects(a, b) {
6917
    var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
6918
    return .999 * dr * dr > dx * dx + dy * dy;
6919
  }
6920
  function d3_layout_packSiblings(node) {
6921
    if (!(nodes = node.children) || !(n = nodes.length)) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6922
    var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as xMin. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
6923
    function bound(node) {
6924
      xMin = Math.min(node.x - node.r, xMin);
6925
      xMax = Math.max(node.x + node.r, xMax);
6926
      yMin = Math.min(node.y - node.r, yMin);
6927
      yMax = Math.max(node.y + node.r, yMax);
6928
    }
6929
    nodes.forEach(d3_layout_packLink);
6930
    a = nodes[0];
6931
    a.x = -a.r;
6932
    a.y = 0;
6933
    bound(a);
6934
    if (n > 1) {
6935
      b = nodes[1];
6936
      b.x = b.r;
6937
      b.y = 0;
6938
      bound(b);
6939
      if (n > 2) {
6940
        c = nodes[2];
6941
        d3_layout_packPlace(a, b, c);
6942
        bound(c);
6943
        d3_layout_packInsert(a, c);
6944
        a._pack_prev = c;
6945
        d3_layout_packInsert(c, b);
6946
        b = a._pack_next;
6947
        for (i = 3; i < n; i++) {
6948
          d3_layout_packPlace(a, b, c = nodes[i]);
6949
          var isect = 0, s1 = 1, s2 = 1;
6950
          for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
6951
            if (d3_layout_packIntersects(j, c)) {
6952
              isect = 1;
6953
              break;
6954
            }
6955
          }
6956
          if (isect == 1) {
6957
            for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
6958
              if (d3_layout_packIntersects(k, c)) {
6959
                break;
6960
              }
6961
            }
6962
          }
6963
          if (isect) {
6964
            if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable k seems to not be initialized for all possible execution paths.
Loading history...
6965
            i--;
6966
          } else {
6967
            d3_layout_packInsert(a, c);
6968
            b = c;
6969
            bound(c);
6970
          }
6971
        }
6972
      }
6973
    }
6974
    var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
6975
    for (i = 0; i < n; i++) {
6976
      c = nodes[i];
6977
      c.x -= cx;
6978
      c.y -= cy;
6979
      cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
6980
    }
6981
    node.r = cr;
6982
    nodes.forEach(d3_layout_packUnlink);
6983
  }
6984
  function d3_layout_packLink(node) {
6985
    node._pack_next = node._pack_prev = node;
6986
  }
6987
  function d3_layout_packUnlink(node) {
6988
    delete node._pack_next;
6989
    delete node._pack_prev;
6990
  }
6991
  function d3_layout_packTransform(node, x, y, k) {
6992
    var children = node.children;
6993
    node.x = x += k * node.x;
6994
    node.y = y += k * node.y;
6995
    node.r *= k;
6996
    if (children) {
6997
      var i = -1, n = children.length;
6998
      while (++i < n) d3_layout_packTransform(children[i], x, y, k);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6999
    }
7000
  }
7001
  function d3_layout_packPlace(a, b, c) {
7002
    var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
7003
    if (db && (dx || dy)) {
7004
      var da = b.r + c.r, dc = dx * dx + dy * dy;
7005
      da *= da;
7006
      db *= db;
7007
      var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
7008
      c.x = a.x + x * dx + y * dy;
7009
      c.y = a.y + x * dy - y * dx;
7010
    } else {
7011
      c.x = a.x + db;
7012
      c.y = a.y;
7013
    }
7014
  }
7015
  d3.layout.tree = function() {
7016
    var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
7017
    function tree(d, i) {
7018
      var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
7019
      d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
7020
      d3_layout_hierarchyVisitBefore(root1, secondWalk);
7021
      if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7022
        var left = root0, right = root0, bottom = root0;
7023
        d3_layout_hierarchyVisitBefore(root0, function(node) {
7024
          if (node.x < left.x) left = node;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7025
          if (node.x > right.x) right = node;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7026
          if (node.depth > bottom.depth) bottom = node;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7027
        });
7028
        var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
7029
        d3_layout_hierarchyVisitBefore(root0, function(node) {
7030
          node.x = (node.x + tx) * kx;
7031
          node.y = node.depth * ky;
7032
        });
7033
      }
7034
      return nodes;
7035
    }
7036
    function wrapTree(root0) {
7037
      var root1 = {
7038
        A: null,
7039
        children: [ root0 ]
7040
      }, queue = [ root1 ], node1;
7041
      while ((node1 = queue.pop()) != null) {
7042
        for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
7043
          queue.push((children[i] = child = {
7044
            _: children[i],
7045
            parent: node1,
7046
            children: (child = children[i].children) && child.slice() || [],
7047
            A: null,
7048
            a: null,
7049
            z: 0,
7050
            m: 0,
7051
            c: 0,
7052
            s: 0,
7053
            t: null,
7054
            i: i
7055
          }).a = child);
0 ignored issues
show
Bug introduced by
The variable child seems to not be initialized for all possible execution paths.
Loading history...
7056
        }
7057
      }
7058
      return root1.children[0];
7059
    }
7060
    function firstWalk(v) {
7061
      var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
7062
      if (children.length) {
7063
        d3_layout_treeShift(v);
7064
        var midpoint = (children[0].z + children[children.length - 1].z) / 2;
7065
        if (w) {
7066
          v.z = w.z + separation(v._, w._);
7067
          v.m = v.z - midpoint;
7068
        } else {
7069
          v.z = midpoint;
7070
        }
7071
      } else if (w) {
7072
        v.z = w.z + separation(v._, w._);
7073
      }
7074
      v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
7075
    }
7076
    function secondWalk(v) {
7077
      v._.x = v.z + v.parent.m;
7078
      v.m += v.parent.m;
7079
    }
7080
    function apportion(v, w, ancestor) {
7081
      if (w) {
7082
        var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
7083
        while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
7084
          vom = d3_layout_treeLeft(vom);
7085
          vop = d3_layout_treeRight(vop);
7086
          vop.a = v;
7087
          shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
7088
          if (shift > 0) {
7089
            d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
7090
            sip += shift;
7091
            sop += shift;
7092
          }
7093
          sim += vim.m;
7094
          sip += vip.m;
7095
          som += vom.m;
7096
          sop += vop.m;
7097
        }
7098
        if (vim && !d3_layout_treeRight(vop)) {
7099
          vop.t = vim;
7100
          vop.m += sim - sop;
7101
        }
7102
        if (vip && !d3_layout_treeLeft(vom)) {
7103
          vom.t = vip;
7104
          vom.m += sip - som;
7105
          ancestor = v;
7106
        }
7107
      }
7108
      return ancestor;
7109
    }
7110
    function sizeNode(node) {
7111
      node.x *= size[0];
7112
      node.y = node.depth * size[1];
7113
    }
7114
    tree.separation = function(x) {
7115
      if (!arguments.length) return separation;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7116
      separation = x;
7117
      return tree;
7118
    };
7119
    tree.size = function(x) {
7120
      if (!arguments.length) return nodeSize ? null : size;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7121
      nodeSize = (size = x) == null ? sizeNode : null;
7122
      return tree;
7123
    };
7124
    tree.nodeSize = function(x) {
7125
      if (!arguments.length) return nodeSize ? size : null;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7126
      nodeSize = (size = x) == null ? null : sizeNode;
7127
      return tree;
7128
    };
7129
    return d3_layout_hierarchyRebind(tree, hierarchy);
7130
  };
7131
  function d3_layout_treeSeparation(a, b) {
7132
    return a.parent == b.parent ? 1 : 2;
7133
  }
7134
  function d3_layout_treeLeft(v) {
7135
    var children = v.children;
7136
    return children.length ? children[0] : v.t;
7137
  }
7138
  function d3_layout_treeRight(v) {
7139
    var children = v.children, n;
7140
    return (n = children.length) ? children[n - 1] : v.t;
7141
  }
7142
  function d3_layout_treeMove(wm, wp, shift) {
7143
    var change = shift / (wp.i - wm.i);
7144
    wp.c -= change;
7145
    wp.s += shift;
7146
    wm.c += change;
7147
    wp.z += shift;
7148
    wp.m += shift;
7149
  }
7150
  function d3_layout_treeShift(v) {
7151
    var shift = 0, change = 0, children = v.children, i = children.length, w;
7152
    while (--i >= 0) {
7153
      w = children[i];
7154
      w.z += shift;
7155
      w.m += shift;
7156
      shift += w.s + (change += w.c);
7157
    }
7158
  }
7159
  function d3_layout_treeAncestor(vim, v, ancestor) {
7160
    return vim.a.parent === v.parent ? vim.a : ancestor;
7161
  }
7162
  d3.layout.cluster = function() {
7163
    var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
7164
    function cluster(d, i) {
7165
      var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
7166
      d3_layout_hierarchyVisitAfter(root, function(node) {
7167
        var children = node.children;
7168
        if (children && children.length) {
7169
          node.x = d3_layout_clusterX(children);
7170
          node.y = d3_layout_clusterY(children);
7171
        } else {
7172
          node.x = previousNode ? x += separation(node, previousNode) : 0;
7173
          node.y = 0;
7174
          previousNode = node;
7175
        }
7176
      });
7177
      var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2;
7178
      d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
7179
        node.x = (node.x - root.x) * size[0];
7180
        node.y = (root.y - node.y) * size[1];
7181
      } : function(node) {
7182
        node.x = (node.x - x0) / (x1 - x0) * size[0];
7183
        node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
7184
      });
7185
      return nodes;
7186
    }
7187
    cluster.separation = function(x) {
7188
      if (!arguments.length) return separation;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7189
      separation = x;
7190
      return cluster;
7191
    };
7192
    cluster.size = function(x) {
7193
      if (!arguments.length) return nodeSize ? null : size;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7194
      nodeSize = (size = x) == null;
7195
      return cluster;
7196
    };
7197
    cluster.nodeSize = function(x) {
7198
      if (!arguments.length) return nodeSize ? size : null;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7199
      nodeSize = (size = x) != null;
7200
      return cluster;
7201
    };
7202
    return d3_layout_hierarchyRebind(cluster, hierarchy);
7203
  };
7204
  function d3_layout_clusterY(children) {
7205
    return 1 + d3.max(children, function(child) {
7206
      return child.y;
7207
    });
7208
  }
7209
  function d3_layout_clusterX(children) {
7210
    return children.reduce(function(x, child) {
7211
      return x + child.x;
7212
    }, 0) / children.length;
7213
  }
7214
  function d3_layout_clusterLeft(node) {
7215
    var children = node.children;
7216
    return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
7217
  }
7218
  function d3_layout_clusterRight(node) {
7219
    var children = node.children, n;
7220
    return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
0 ignored issues
show
Bug introduced by
The variable n seems to not be initialized for all possible execution paths.
Loading history...
7221
  }
7222
  d3.layout.treemap = function() {
7223
    var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5));
7224
    function scale(children, k) {
7225
      var i = -1, n = children.length, child, area;
7226
      while (++i < n) {
7227
        area = (child = children[i]).value * (k < 0 ? 0 : k);
7228
        child.area = isNaN(area) || area <= 0 ? 0 : area;
7229
      }
7230
    }
7231
    function squarify(node) {
7232
      var children = node.children;
7233
      if (children && children.length) {
7234
        var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as best. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
7235
        scale(remaining, rect.dx * rect.dy / node.value);
7236
        row.area = 0;
7237
        while ((n = remaining.length) > 0) {
7238
          row.push(child = remaining[n - 1]);
7239
          row.area += child.area;
7240
          if (mode !== "squarify" || (score = worst(row, u)) <= best) {
7241
            remaining.pop();
7242
            best = score;
0 ignored issues
show
Bug introduced by
The variable score seems to not be initialized for all possible execution paths.
Loading history...
7243
          } else {
7244
            row.area -= row.pop().area;
7245
            position(row, u, rect, false);
7246
            u = Math.min(rect.dx, rect.dy);
7247
            row.length = row.area = 0;
7248
            best = Infinity;
7249
          }
7250
        }
7251
        if (row.length) {
7252
          position(row, u, rect, true);
7253
          row.length = row.area = 0;
7254
        }
7255
        children.forEach(squarify);
7256
      }
7257
    }
7258
    function stickify(node) {
7259
      var children = node.children;
7260
      if (children && children.length) {
7261
        var rect = pad(node), remaining = children.slice(), child, row = [];
7262
        scale(remaining, rect.dx * rect.dy / node.value);
7263
        row.area = 0;
7264
        while (child = remaining.pop()) {
7265
          row.push(child);
7266
          row.area += child.area;
7267
          if (child.z != null) {
7268
            position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
7269
            row.length = row.area = 0;
7270
          }
7271
        }
7272
        children.forEach(stickify);
7273
      }
7274
    }
7275
    function worst(row, u) {
7276
      var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as rmin. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
7277
      while (++i < n) {
7278
        if (!(r = row[i].area)) continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7279
        if (r < rmin) rmin = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7280
        if (r > rmax) rmax = r;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7281
      }
7282
      s *= s;
7283
      u *= u;
7284
      return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
7285
    }
7286
    function position(row, u, rect, flush) {
7287
      var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
7288
      if (u == rect.dx) {
7289
        if (flush || v > rect.dy) v = rect.dy;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7290
        while (++i < n) {
7291
          o = row[i];
7292
          o.x = x;
7293
          o.y = y;
7294
          o.dy = v;
7295
          x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
7296
        }
7297
        o.z = true;
0 ignored issues
show
Bug introduced by
The variable o seems to not be initialized for all possible execution paths.
Loading history...
7298
        o.dx += rect.x + rect.dx - x;
7299
        rect.y += v;
7300
        rect.dy -= v;
7301
      } else {
7302
        if (flush || v > rect.dx) v = rect.dx;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7303
        while (++i < n) {
7304
          o = row[i];
7305
          o.x = x;
7306
          o.y = y;
7307
          o.dx = v;
7308
          y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
7309
        }
7310
        o.z = false;
7311
        o.dy += rect.y + rect.dy - y;
7312
        rect.x += v;
7313
        rect.dx -= v;
7314
      }
7315
    }
7316
    function treemap(d) {
7317
      var nodes = stickies || hierarchy(d), root = nodes[0];
7318
      root.x = 0;
7319
      root.y = 0;
7320
      root.dx = size[0];
7321
      root.dy = size[1];
7322
      if (stickies) hierarchy.revalue(root);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7323
      scale([ root ], root.dx * root.dy / root.value);
7324
      (stickies ? stickify : squarify)(root);
7325
      if (sticky) stickies = nodes;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7326
      return nodes;
7327
    }
7328
    treemap.size = function(x) {
7329
      if (!arguments.length) return size;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7330
      size = x;
7331
      return treemap;
7332
    };
7333
    treemap.padding = function(x) {
7334
      if (!arguments.length) return padding;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7335
      function padFunction(node) {
7336
        var p = x.call(treemap, node, node.depth);
7337
        return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
7338
      }
7339
      function padConstant(node) {
7340
        return d3_layout_treemapPad(node, x);
7341
      }
7342
      var type;
7343
      pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ], 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
7344
      padConstant) : padConstant;
7345
      return treemap;
7346
    };
7347
    treemap.round = function(x) {
7348
      if (!arguments.length) return round != Number;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7349
      round = x ? Math.round : Number;
7350
      return treemap;
7351
    };
7352
    treemap.sticky = function(x) {
7353
      if (!arguments.length) return sticky;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7354
      sticky = x;
7355
      stickies = null;
7356
      return treemap;
7357
    };
7358
    treemap.ratio = function(x) {
7359
      if (!arguments.length) return ratio;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7360
      ratio = x;
7361
      return treemap;
7362
    };
7363
    treemap.mode = function(x) {
7364
      if (!arguments.length) return mode;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7365
      mode = x + "";
7366
      return treemap;
7367
    };
7368
    return d3_layout_hierarchyRebind(treemap, hierarchy);
7369
  };
7370
  function d3_layout_treemapPadNull(node) {
7371
    return {
7372
      x: node.x,
7373
      y: node.y,
7374
      dx: node.dx,
7375
      dy: node.dy
7376
    };
7377
  }
7378
  function d3_layout_treemapPad(node, padding) {
7379
    var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2];
7380
    if (dx < 0) {
7381
      x += dx / 2;
7382
      dx = 0;
7383
    }
7384
    if (dy < 0) {
7385
      y += dy / 2;
7386
      dy = 0;
7387
    }
7388
    return {
7389
      x: x,
7390
      y: y,
7391
      dx: dx,
7392
      dy: dy
7393
    };
7394
  }
7395
  d3.random = {
7396
    normal: function(µ, σ) {
7397
      var n = arguments.length;
7398
      if (n < 2) σ = 1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7399
      if (n < 1) µ = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7400
      return function() {
7401
        var x, y, r;
7402
        do {
7403
          x = Math.random() * 2 - 1;
7404
          y = Math.random() * 2 - 1;
7405
          r = x * x + y * y;
7406
        } while (!r || r > 1);
7407
        return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
7408
      };
7409
    },
7410
    logNormal: function() {
7411
      var random = d3.random.normal.apply(d3, arguments);
7412
      return function() {
7413
        return Math.exp(random());
7414
      };
7415
    },
7416
    bates: function(m) {
7417
      var random = d3.random.irwinHall(m);
7418
      return function() {
7419
        return random() / m;
7420
      };
7421
    },
7422
    irwinHall: function(m) {
7423
      return function() {
7424
        for (var s = 0, j = 0; j < m; j++) s += Math.random();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7425
        return s;
7426
      };
7427
    }
7428
  };
7429
  d3.scale = {};
7430
  function d3_scaleExtent(domain) {
7431
    var start = domain[0], stop = domain[domain.length - 1];
7432
    return start < stop ? [ start, stop ] : [ stop, start ];
7433
  }
7434
  function d3_scaleRange(scale) {
7435
    return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
7436
  }
7437
  function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
7438
    var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
7439
    return function(x) {
7440
      return i(u(x));
7441
    };
7442
  }
7443
  function d3_scale_nice(domain, nice) {
7444
    var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
7445
    if (x1 < x0) {
7446
      dx = i0, i0 = i1, i1 = dx;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
7447
      dx = x0, x0 = x1, x1 = dx;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
7448
    }
7449
    domain[i0] = nice.floor(x0);
7450
    domain[i1] = nice.ceil(x1);
7451
    return domain;
7452
  }
7453
  function d3_scale_niceStep(step) {
7454
    return step ? {
7455
      floor: function(x) {
7456
        return Math.floor(x / step) * step;
7457
      },
7458
      ceil: function(x) {
7459
        return Math.ceil(x / step) * step;
7460
      }
7461
    } : d3_scale_niceIdentity;
7462
  }
7463
  var d3_scale_niceIdentity = {
7464
    floor: d3_identity,
7465
    ceil: d3_identity
7466
  };
7467
  function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
7468
    var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
7469
    if (domain[k] < domain[0]) {
7470
      domain = domain.slice().reverse();
7471
      range = range.slice().reverse();
7472
    }
7473
    while (++j <= k) {
7474
      u.push(uninterpolate(domain[j - 1], domain[j]));
7475
      i.push(interpolate(range[j - 1], range[j]));
7476
    }
7477
    return function(x) {
7478
      var j = d3.bisect(domain, x, 1, k) - 1;
7479
      return i[j](u[j](x));
7480
    };
7481
  }
7482
  d3.scale.linear = function() {
7483
    return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
7484
  };
7485
  function d3_scale_linear(domain, range, interpolate, clamp) {
7486
    var output, input;
7487
    function rescale() {
7488
      var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
7489
      output = linear(domain, range, uninterpolate, interpolate);
7490
      input = linear(range, domain, uninterpolate, d3_interpolate);
7491
      return scale;
7492
    }
7493
    function scale(x) {
7494
      return output(x);
7495
    }
7496
    scale.invert = function(y) {
7497
      return input(y);
7498
    };
7499
    scale.domain = function(x) {
7500
      if (!arguments.length) return domain;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7501
      domain = x.map(Number);
7502
      return rescale();
7503
    };
7504
    scale.range = function(x) {
7505
      if (!arguments.length) return range;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7506
      range = x;
7507
      return rescale();
7508
    };
7509
    scale.rangeRound = function(x) {
7510
      return scale.range(x).interpolate(d3_interpolateRound);
7511
    };
7512
    scale.clamp = function(x) {
7513
      if (!arguments.length) return clamp;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7514
      clamp = x;
7515
      return rescale();
7516
    };
7517
    scale.interpolate = function(x) {
7518
      if (!arguments.length) return interpolate;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7519
      interpolate = x;
7520
      return rescale();
7521
    };
7522
    scale.ticks = function(m) {
7523
      return d3_scale_linearTicks(domain, m);
7524
    };
7525
    scale.tickFormat = function(m, format) {
7526
      return d3_scale_linearTickFormat(domain, m, format);
7527
    };
7528
    scale.nice = function(m) {
7529
      d3_scale_linearNice(domain, m);
7530
      return rescale();
7531
    };
7532
    scale.copy = function() {
7533
      return d3_scale_linear(domain, range, interpolate, clamp);
7534
    };
7535
    return rescale();
7536
  }
7537
  function d3_scale_linearRebind(scale, linear) {
7538
    return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
7539
  }
7540
  function d3_scale_linearNice(domain, m) {
7541
    return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
7542
  }
7543
  function d3_scale_linearTickRange(domain, m) {
7544
    if (m == null) m = 10;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7545
    var extent = d3_scaleExtent(domain), span = extent[1] - extent[0], step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), err = m / span * step;
7546
    if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7547
    extent[0] = Math.ceil(extent[0] / step) * step;
7548
    extent[1] = Math.floor(extent[1] / step) * step + step * .5;
7549
    extent[2] = step;
7550
    return extent;
7551
  }
7552
  function d3_scale_linearTicks(domain, m) {
7553
    return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
7554
  }
7555
  function d3_scale_linearTickFormat(domain, m, format) {
7556
    var range = d3_scale_linearTickRange(domain, m);
7557
    if (format) {
7558
      var match = d3_format_re.exec(format);
7559
      match.shift();
7560
      if (match[8] === "s") {
7561
        var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
7562
        if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7563
        match[8] = "f";
7564
        format = d3.format(match.join(""));
7565
        return function(d) {
7566
          return format(prefix.scale(d)) + prefix.symbol;
7567
        };
7568
      }
7569
      if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7570
      format = match.join("");
7571
    } else {
7572
      format = ",." + d3_scale_linearPrecision(range[2]) + "f";
7573
    }
7574
    return d3.format(format);
7575
  }
7576
  var d3_scale_linearFormatSignificant = {
7577
    s: 1,
7578
    g: 1,
7579
    p: 1,
7580
    r: 1,
7581
    e: 1
7582
  };
7583
  function d3_scale_linearPrecision(value) {
7584
    return -Math.floor(Math.log(value) / Math.LN10 + .01);
7585
  }
7586
  function d3_scale_linearFormatPrecision(type, range) {
7587
    var p = d3_scale_linearPrecision(range[2]);
7588
    return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
7589
  }
7590
  d3.scale.log = function() {
7591
    return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
7592
  };
7593
  function d3_scale_log(linear, base, positive, domain) {
7594
    function log(x) {
7595
      return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
7596
    }
7597
    function pow(x) {
7598
      return positive ? Math.pow(base, x) : -Math.pow(base, -x);
7599
    }
7600
    function scale(x) {
7601
      return linear(log(x));
7602
    }
7603
    scale.invert = function(x) {
7604
      return pow(linear.invert(x));
7605
    };
7606
    scale.domain = function(x) {
7607
      if (!arguments.length) return domain;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7608
      positive = x[0] >= 0;
7609
      linear.domain((domain = x.map(Number)).map(log));
7610
      return scale;
7611
    };
7612
    scale.base = function(_) {
7613
      if (!arguments.length) return base;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7614
      base = +_;
7615
      linear.domain(domain.map(log));
7616
      return scale;
7617
    };
7618
    scale.nice = function() {
7619
      var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
7620
      linear.domain(niced);
7621
      domain = niced.map(pow);
7622
      return scale;
7623
    };
7624
    scale.ticks = function() {
7625
      var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
7626
      if (isFinite(j - i)) {
7627
        if (positive) {
7628
          for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7629
          ticks.push(pow(i));
7630
        } else {
7631
          ticks.push(pow(i));
7632
          for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable k already seems to be declared on line 7628. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7633
        }
7634
        for (i = 0; ticks[i] < u; i++) {}
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
7635
        for (j = ticks.length; ticks[j - 1] > v; j--) {}
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
7636
        ticks = ticks.slice(i, j);
7637
      }
7638
      return ticks;
7639
    };
7640
    scale.tickFormat = function(n, format) {
7641
      if (!arguments.length) return d3_scale_logFormat;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7642
      if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7643
      var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12, 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
7644
      Math.floor), e;
7645
      return function(d) {
7646
        return d / pow(f(log(d) + e)) <= k ? format(d) : "";
7647
      };
7648
    };
7649
    scale.copy = function() {
7650
      return d3_scale_log(linear.copy(), base, positive, domain);
7651
    };
7652
    return d3_scale_linearRebind(scale, linear);
7653
  }
7654
  var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
7655
    floor: function(x) {
7656
      return -Math.ceil(-x);
7657
    },
7658
    ceil: function(x) {
7659
      return -Math.floor(-x);
7660
    }
7661
  };
7662
  d3.scale.pow = function() {
7663
    return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
7664
  };
7665
  function d3_scale_pow(linear, exponent, domain) {
7666
    var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
7667
    function scale(x) {
7668
      return linear(powp(x));
7669
    }
7670
    scale.invert = function(x) {
7671
      return powb(linear.invert(x));
7672
    };
7673
    scale.domain = function(x) {
7674
      if (!arguments.length) return domain;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7675
      linear.domain((domain = x.map(Number)).map(powp));
7676
      return scale;
7677
    };
7678
    scale.ticks = function(m) {
7679
      return d3_scale_linearTicks(domain, m);
7680
    };
7681
    scale.tickFormat = function(m, format) {
7682
      return d3_scale_linearTickFormat(domain, m, format);
7683
    };
7684
    scale.nice = function(m) {
7685
      return scale.domain(d3_scale_linearNice(domain, m));
7686
    };
7687
    scale.exponent = function(x) {
7688
      if (!arguments.length) return exponent;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7689
      powp = d3_scale_powPow(exponent = x);
7690
      powb = d3_scale_powPow(1 / exponent);
7691
      linear.domain(domain.map(powp));
7692
      return scale;
7693
    };
7694
    scale.copy = function() {
7695
      return d3_scale_pow(linear.copy(), exponent, domain);
7696
    };
7697
    return d3_scale_linearRebind(scale, linear);
7698
  }
7699
  function d3_scale_powPow(e) {
7700
    return function(x) {
7701
      return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
7702
    };
7703
  }
7704
  d3.scale.sqrt = function() {
7705
    return d3.scale.pow().exponent(.5);
7706
  };
7707
  d3.scale.ordinal = function() {
7708
    return d3_scale_ordinal([], {
7709
      t: "range",
7710
      a: [ [] ]
7711
    });
7712
  };
7713
  function d3_scale_ordinal(domain, ranger) {
7714
    var index, range, rangeBand;
7715
    function scale(x) {
7716
      return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
7717
    }
7718
    function steps(start, step) {
7719
      return d3.range(domain.length).map(function(i) {
7720
        return start + step * i;
7721
      });
7722
    }
7723
    scale.domain = function(x) {
7724
      if (!arguments.length) return domain;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7725
      domain = [];
7726
      index = new d3_Map();
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_Map should be capitalized.
Loading history...
7727
      var i = -1, n = x.length, xi;
7728
      while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7729
      return scale[ranger.t].apply(scale, ranger.a);
7730
    };
7731
    scale.range = function(x) {
7732
      if (!arguments.length) return range;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7733
      range = x;
7734
      rangeBand = 0;
7735
      ranger = {
7736
        t: "range",
7737
        a: arguments
7738
      };
7739
      return scale;
7740
    };
7741
    scale.rangePoints = function(x, padding) {
7742
      if (arguments.length < 2) padding = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7743
      var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2, 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
7744
      0) : (stop - start) / (domain.length - 1 + padding);
7745
      range = steps(start + step * padding / 2, step);
7746
      rangeBand = 0;
7747
      ranger = {
7748
        t: "rangePoints",
7749
        a: arguments
7750
      };
7751
      return scale;
7752
    };
7753
    scale.rangeRoundPoints = function(x, padding) {
7754
      if (arguments.length < 2) padding = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7755
      var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2), 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
7756
      0) : (stop - start) / (domain.length - 1 + padding) | 0;
7757
      range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
7758
      rangeBand = 0;
7759
      ranger = {
7760
        t: "rangeRoundPoints",
7761
        a: arguments
7762
      };
7763
      return scale;
7764
    };
7765
    scale.rangeBands = function(x, padding, outerPadding) {
7766
      if (arguments.length < 2) padding = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7767
      if (arguments.length < 3) outerPadding = padding;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7768
      var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
7769
      range = steps(start + step * outerPadding, step);
7770
      if (reverse) range.reverse();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7771
      rangeBand = step * (1 - padding);
7772
      ranger = {
7773
        t: "rangeBands",
7774
        a: arguments
7775
      };
7776
      return scale;
7777
    };
7778
    scale.rangeRoundBands = function(x, padding, outerPadding) {
7779
      if (arguments.length < 2) padding = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7780
      if (arguments.length < 3) outerPadding = padding;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7781
      var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
7782
      range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
7783
      if (reverse) range.reverse();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7784
      rangeBand = Math.round(step * (1 - padding));
7785
      ranger = {
7786
        t: "rangeRoundBands",
7787
        a: arguments
7788
      };
7789
      return scale;
7790
    };
7791
    scale.rangeBand = function() {
7792
      return rangeBand;
7793
    };
7794
    scale.rangeExtent = function() {
7795
      return d3_scaleExtent(ranger.a[0]);
7796
    };
7797
    scale.copy = function() {
7798
      return d3_scale_ordinal(domain, ranger);
7799
    };
7800
    return scale.domain(domain);
7801
  }
7802
  d3.scale.category10 = function() {
7803
    return d3.scale.ordinal().range(d3_category10);
7804
  };
7805
  d3.scale.category20 = function() {
7806
    return d3.scale.ordinal().range(d3_category20);
7807
  };
7808
  d3.scale.category20b = function() {
7809
    return d3.scale.ordinal().range(d3_category20b);
7810
  };
7811
  d3.scale.category20c = function() {
7812
    return d3.scale.ordinal().range(d3_category20c);
7813
  };
7814
  var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
7815
  var d3_category20 = [ 2062260, 11454440, 16744206, 16759672, 2924588, 10018698, 14034728, 16750742, 9725885, 12955861, 9197131, 12885140, 14907330, 16234194, 8355711, 13092807, 12369186, 14408589, 1556175, 10410725 ].map(d3_rgbString);
7816
  var d3_category20b = [ 3750777, 5395619, 7040719, 10264286, 6519097, 9216594, 11915115, 13556636, 9202993, 12426809, 15186514, 15190932, 8666169, 11356490, 14049643, 15177372, 8077683, 10834324, 13528509, 14589654 ].map(d3_rgbString);
7817
  var d3_category20c = [ 3244733, 7057110, 10406625, 13032431, 15095053, 16616764, 16625259, 16634018, 3253076, 7652470, 10607003, 13101504, 7695281, 10394312, 12369372, 14342891, 6513507, 9868950, 12434877, 14277081 ].map(d3_rgbString);
7818
  d3.scale.quantile = function() {
7819
    return d3_scale_quantile([], []);
7820
  };
7821
  function d3_scale_quantile(domain, range) {
7822
    var thresholds;
7823
    function rescale() {
7824
      var k = 0, q = range.length;
7825
      thresholds = [];
7826
      while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7827
      return scale;
7828
    }
7829
    function scale(x) {
7830
      if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity Best Practice introduced by
There is no return statement if !isNaN(x = +x) is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
7831
    }
7832
    scale.domain = function(x) {
7833
      if (!arguments.length) return domain;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7834
      domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
7835
      return rescale();
7836
    };
7837
    scale.range = function(x) {
7838
      if (!arguments.length) return range;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7839
      range = x;
7840
      return rescale();
7841
    };
7842
    scale.quantiles = function() {
7843
      return thresholds;
7844
    };
7845
    scale.invertExtent = function(y) {
7846
      y = range.indexOf(y);
7847
      return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
7848
    };
7849
    scale.copy = function() {
7850
      return d3_scale_quantile(domain, range);
7851
    };
7852
    return rescale();
7853
  }
7854
  d3.scale.quantize = function() {
7855
    return d3_scale_quantize(0, 1, [ 0, 1 ]);
7856
  };
7857
  function d3_scale_quantize(x0, x1, range) {
7858
    var kx, i;
7859
    function scale(x) {
7860
      return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
7861
    }
7862
    function rescale() {
7863
      kx = range.length / (x1 - x0);
7864
      i = range.length - 1;
7865
      return scale;
7866
    }
7867
    scale.domain = function(x) {
7868
      if (!arguments.length) return [ x0, x1 ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7869
      x0 = +x[0];
7870
      x1 = +x[x.length - 1];
7871
      return rescale();
7872
    };
7873
    scale.range = function(x) {
7874
      if (!arguments.length) return range;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7875
      range = x;
7876
      return rescale();
7877
    };
7878
    scale.invertExtent = function(y) {
7879
      y = range.indexOf(y);
7880
      y = y < 0 ? NaN : y / kx + x0;
7881
      return [ y, y + 1 / kx ];
7882
    };
7883
    scale.copy = function() {
7884
      return d3_scale_quantize(x0, x1, range);
7885
    };
7886
    return rescale();
7887
  }
7888
  d3.scale.threshold = function() {
7889
    return d3_scale_threshold([ .5 ], [ 0, 1 ]);
7890
  };
7891
  function d3_scale_threshold(domain, range) {
7892
    function scale(x) {
7893
      if (x <= x) return range[d3.bisect(domain, x)];
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if x <= x is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7894
    }
7895
    scale.domain = function(_) {
7896
      if (!arguments.length) return domain;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7897
      domain = _;
7898
      return scale;
7899
    };
7900
    scale.range = function(_) {
7901
      if (!arguments.length) return range;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7902
      range = _;
7903
      return scale;
7904
    };
7905
    scale.invertExtent = function(y) {
7906
      y = range.indexOf(y);
7907
      return [ domain[y - 1], domain[y] ];
7908
    };
7909
    scale.copy = function() {
7910
      return d3_scale_threshold(domain, range);
7911
    };
7912
    return scale;
7913
  }
7914
  d3.scale.identity = function() {
7915
    return d3_scale_identity([ 0, 1 ]);
7916
  };
7917
  function d3_scale_identity(domain) {
7918
    function identity(x) {
7919
      return +x;
7920
    }
7921
    identity.invert = identity;
7922
    identity.domain = identity.range = function(x) {
7923
      if (!arguments.length) return domain;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7924
      domain = x.map(identity);
7925
      return identity;
7926
    };
7927
    identity.ticks = function(m) {
7928
      return d3_scale_linearTicks(domain, m);
7929
    };
7930
    identity.tickFormat = function(m, format) {
7931
      return d3_scale_linearTickFormat(domain, m, format);
7932
    };
7933
    identity.copy = function() {
7934
      return d3_scale_identity(domain);
7935
    };
7936
    return identity;
7937
  }
7938
  d3.svg = {};
7939
  function d3_zero() {
7940
    return 0;
7941
  }
7942
  d3.svg.arc = function() {
7943
    var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
7944
    function arc() {
7945
      var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
7946
      if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
7947
      if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7948
      var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
7949
      if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
7950
        rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
7951
        if (!cw) p1 *= -1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7952
        if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7953
        if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7954
      }
7955 View Code Duplication
      if (r1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7956
        x0 = r1 * Math.cos(a0 + p1);
7957
        y0 = r1 * Math.sin(a0 + p1);
7958
        x1 = r1 * Math.cos(a1 - p1);
7959
        y1 = r1 * Math.sin(a1 - p1);
7960
        var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
7961
        if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
7962
          var h1 = (a0 + a1) / 2;
7963
          x0 = r1 * Math.cos(h1);
7964
          y0 = r1 * Math.sin(h1);
7965
          x1 = y1 = null;
7966
        }
7967
      } else {
7968
        x0 = y0 = 0;
7969
      }
7970 View Code Duplication
      if (r0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7971
        x2 = r0 * Math.cos(a1 - p0);
7972
        y2 = r0 * Math.sin(a1 - p0);
7973
        x3 = r0 * Math.cos(a0 + p0);
7974
        y3 = r0 * Math.sin(a0 + p0);
7975
        var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
7976
        if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
7977
          var h0 = (a0 + a1) / 2;
7978
          x2 = r0 * Math.cos(h0);
7979
          y2 = r0 * Math.sin(h0);
7980
          x3 = y3 = null;
7981
        }
7982
      } else {
7983
        x2 = y2 = 0;
7984
      }
7985
      if ((rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
7986
        cr = r0 < r1 ^ cw ? 0 : 1;
7987
        var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
0 ignored issues
show
Bug introduced by
The variable x3 seems to not be initialized for all possible execution paths.
Loading history...
Bug introduced by
The variable y3 seems to not be initialized for all possible execution paths.
Loading history...
Bug introduced by
The variable x1 seems to not be initialized for all possible execution paths.
Loading history...
Bug introduced by
The variable y1 seems to not be initialized for all possible execution paths.
Loading history...
7988
        if (x1 != null) {
7989
          var rc1 = Math.min(rc, (r1 - lc) / (kc + 1)), t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
7990
          if (rc === rc1) {
7991
            path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
7992
          } else {
7993
            path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
7994
          }
7995
        } else {
7996
          path.push("M", x0, ",", y0);
7997
        }
7998
        if (x3 != null) {
7999
          var rc0 = Math.min(rc, (r0 - lc) / (kc - 1)), t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
8000
          if (rc === rc0) {
8001
            path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
8002
          } else {
8003
            path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
8004
          }
8005
        } else {
8006
          path.push("L", x2, ",", y2);
8007
        }
8008
      } else {
8009
        path.push("M", x0, ",", y0);
8010
        if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
0 ignored issues
show
Bug introduced by
The variable l1 seems to not be initialized for all possible execution paths. Are you sure push handles undefined variables?
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8011
        path.push("L", x2, ",", y2);
8012
        if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable l0 seems to not be initialized for all possible execution paths. Are you sure push handles undefined variables?
Loading history...
8013
      }
8014
      path.push("Z");
8015
      return path.join("");
8016
    }
8017
    function circleSegment(r1, cw) {
8018
      return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
8019
    }
8020
    arc.innerRadius = function(v) {
8021
      if (!arguments.length) return innerRadius;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8022
      innerRadius = d3_functor(v);
8023
      return arc;
8024
    };
8025
    arc.outerRadius = function(v) {
8026
      if (!arguments.length) return outerRadius;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8027
      outerRadius = d3_functor(v);
8028
      return arc;
8029
    };
8030
    arc.cornerRadius = function(v) {
8031
      if (!arguments.length) return cornerRadius;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8032
      cornerRadius = d3_functor(v);
8033
      return arc;
8034
    };
8035
    arc.padRadius = function(v) {
8036
      if (!arguments.length) return padRadius;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8037
      padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
8038
      return arc;
8039
    };
8040
    arc.startAngle = function(v) {
8041
      if (!arguments.length) return startAngle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8042
      startAngle = d3_functor(v);
8043
      return arc;
8044
    };
8045
    arc.endAngle = function(v) {
8046
      if (!arguments.length) return endAngle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8047
      endAngle = d3_functor(v);
8048
      return arc;
8049
    };
8050
    arc.padAngle = function(v) {
8051
      if (!arguments.length) return padAngle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8052
      padAngle = d3_functor(v);
8053
      return arc;
8054
    };
8055
    arc.centroid = function() {
8056
      var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
8057
      return [ Math.cos(a) * r, Math.sin(a) * r ];
8058
    };
8059
    return arc;
8060
  };
8061
  var d3_svg_arcAuto = "auto";
8062
  function d3_svg_arcInnerRadius(d) {
8063
    return d.innerRadius;
8064
  }
8065
  function d3_svg_arcOuterRadius(d) {
8066
    return d.outerRadius;
8067
  }
8068
  function d3_svg_arcStartAngle(d) {
8069
    return d.startAngle;
8070
  }
8071
  function d3_svg_arcEndAngle(d) {
8072
    return d.endAngle;
8073
  }
8074
  function d3_svg_arcPadAngle(d) {
8075
    return d && d.padAngle;
8076
  }
8077
  function d3_svg_arcSweep(x0, y0, x1, y1) {
8078
    return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
8079
  }
8080
  function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
8081
    var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(r * r * d2 - D * D), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
8082
    if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8083
    return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
8084
  }
8085
  function d3_svg_line(projection) {
8086
    var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
8087
    function line(data) {
8088
      var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
8089
      function segment() {
8090
        segments.push("M", interpolate(projection(points), tension));
8091
      }
8092
      while (++i < n) {
8093
        if (defined.call(this, d = data[i], i)) {
8094
          points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
8095
        } else if (points.length) {
8096
          segment();
8097
          points = [];
8098
        }
8099
      }
8100
      if (points.length) segment();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8101
      return segments.length ? segments.join("") : null;
8102
    }
8103
    line.x = function(_) {
8104
      if (!arguments.length) return x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8105
      x = _;
8106
      return line;
8107
    };
8108
    line.y = function(_) {
8109
      if (!arguments.length) return y;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8110
      y = _;
8111
      return line;
8112
    };
8113
    line.defined = function(_) {
8114
      if (!arguments.length) return defined;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8115
      defined = _;
8116
      return line;
8117
    };
8118
    line.interpolate = function(_) {
8119
      if (!arguments.length) return interpolateKey;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8120
      if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8121
      return line;
8122
    };
8123
    line.tension = function(_) {
8124
      if (!arguments.length) return tension;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8125
      tension = _;
8126
      return line;
8127
    };
8128
    return line;
8129
  }
8130
  d3.svg.line = function() {
8131
    return d3_svg_line(d3_identity);
8132
  };
8133
  var d3_svg_lineInterpolators = d3.map({
8134
    linear: d3_svg_lineLinear,
8135
    "linear-closed": d3_svg_lineLinearClosed,
8136
    step: d3_svg_lineStep,
8137
    "step-before": d3_svg_lineStepBefore,
8138
    "step-after": d3_svg_lineStepAfter,
8139
    basis: d3_svg_lineBasis,
8140
    "basis-open": d3_svg_lineBasisOpen,
8141
    "basis-closed": d3_svg_lineBasisClosed,
8142
    bundle: d3_svg_lineBundle,
8143
    cardinal: d3_svg_lineCardinal,
8144
    "cardinal-open": d3_svg_lineCardinalOpen,
8145
    "cardinal-closed": d3_svg_lineCardinalClosed,
8146
    monotone: d3_svg_lineMonotone
8147
  });
8148
  d3_svg_lineInterpolators.forEach(function(key, value) {
8149
    value.key = key;
8150
    value.closed = /-closed$/.test(key);
8151
  });
8152
  function d3_svg_lineLinear(points) {
8153
    return points.join("L");
8154
  }
8155
  function d3_svg_lineLinearClosed(points) {
8156
    return d3_svg_lineLinear(points) + "Z";
8157
  }
8158
  function d3_svg_lineStep(points) {
8159
    var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8160
    while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8161
    if (n > 1) path.push("H", p[0]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8162
    return path.join("");
8163
  }
8164
  function d3_svg_lineStepBefore(points) {
8165
    var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8166
    while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8167
    return path.join("");
8168
  }
8169
  function d3_svg_lineStepAfter(points) {
8170
    var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8171
    while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8172
    return path.join("");
8173
  }
8174
  function d3_svg_lineCardinalOpen(points, tension) {
8175
    return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
8176
  }
8177
  function d3_svg_lineCardinalClosed(points, tension) {
8178
    return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]), 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8179
    points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
8180
  }
8181
  function d3_svg_lineCardinal(points, tension) {
8182
    return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
8183
  }
8184
  function d3_svg_lineHermite(points, tangents) {
8185
    if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
8186
      return d3_svg_lineLinear(points);
8187
    }
8188
    var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
8189
    if (quad) {
8190
      path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
8191
      p0 = points[1];
8192
      pi = 2;
8193
    }
8194
    if (tangents.length > 1) {
8195
      t = tangents[1];
8196
      p = points[pi];
8197
      pi++;
8198
      path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8199
      for (var i = 2; i < tangents.length; i++, pi++) {
8200
        p = points[pi];
8201
        t = tangents[i];
8202
        path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8203
      }
8204
    }
8205
    if (quad) {
8206
      var lp = points[pi];
8207
      path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
8208
    }
8209
    return path;
8210
  }
8211
  function d3_svg_lineCardinalTangents(points, tension) {
8212
    var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
8213
    while (++i < n) {
8214
      p0 = p1;
8215
      p1 = p2;
8216
      p2 = points[i];
8217
      tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
8218
    }
8219
    return tangents;
8220
  }
8221
  function d3_svg_lineBasis(points) {
8222
    if (points.length < 3) return d3_svg_lineLinear(points);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8223
    var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
8224
    points.push(points[n - 1]);
8225
    while (++i <= n) {
8226
      pi = points[i];
8227
      px.shift();
8228
      px.push(pi[0]);
8229
      py.shift();
8230
      py.push(pi[1]);
8231
      d3_svg_lineBasisBezier(path, px, py);
8232
    }
8233
    points.pop();
8234
    path.push("L", pi);
8235
    return path.join("");
8236
  }
8237
  function d3_svg_lineBasisOpen(points) {
8238
    if (points.length < 4) return d3_svg_lineLinear(points);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8239
    var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
8240
    while (++i < 3) {
8241
      pi = points[i];
8242
      px.push(pi[0]);
8243
      py.push(pi[1]);
8244
    }
8245
    path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
8246
    --i;
8247
    while (++i < n) {
8248
      pi = points[i];
8249
      px.shift();
8250
      px.push(pi[0]);
8251
      py.shift();
8252
      py.push(pi[1]);
8253
      d3_svg_lineBasisBezier(path, px, py);
8254
    }
8255
    return path.join("");
8256
  }
8257
  function d3_svg_lineBasisClosed(points) {
8258
    var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
8259
    while (++i < 4) {
8260
      pi = points[i % n];
8261
      px.push(pi[0]);
8262
      py.push(pi[1]);
8263
    }
8264
    path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
8265
    --i;
8266
    while (++i < m) {
8267
      pi = points[i % n];
8268
      px.shift();
8269
      px.push(pi[0]);
8270
      py.shift();
8271
      py.push(pi[1]);
8272
      d3_svg_lineBasisBezier(path, px, py);
8273
    }
8274
    return path.join("");
8275
  }
8276
  function d3_svg_lineBundle(points, tension) {
8277
    var n = points.length - 1;
8278
    if (n) {
8279
      var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
8280
      while (++i <= n) {
8281
        p = points[i];
8282
        t = i / n;
8283
        p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
8284
        p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
8285
      }
8286
    }
8287
    return d3_svg_lineBasis(points);
8288
  }
8289
  function d3_svg_lineDot4(a, b) {
8290
    return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
8291
  }
8292
  var d3_svg_lineBasisBezier1 = [ 0, 2 / 3, 1 / 3, 0 ], d3_svg_lineBasisBezier2 = [ 0, 1 / 3, 2 / 3, 0 ], d3_svg_lineBasisBezier3 = [ 0, 1 / 6, 2 / 3, 1 / 6 ];
8293
  function d3_svg_lineBasisBezier(path, x, y) {
8294
    path.push("C", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y));
8295
  }
8296
  function d3_svg_lineSlope(p0, p1) {
8297
    return (p1[1] - p0[1]) / (p1[0] - p0[0]);
8298
  }
8299
  function d3_svg_lineFiniteDifferences(points) {
8300
    var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
8301
    while (++i < j) {
8302
      m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
0 ignored issues
show
Unused Code introduced by
The assignment to variable p0 seems to be never used. Consider removing it.
Loading history...
8303
    }
8304
    m[i] = d;
8305
    return m;
8306
  }
8307
  function d3_svg_lineMonotoneTangents(points) {
8308
    var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
8309
    while (++i < j) {
8310
      d = d3_svg_lineSlope(points[i], points[i + 1]);
8311
      if (abs(d) < ε) {
8312
        m[i] = m[i + 1] = 0;
8313
      } else {
8314
        a = m[i] / d;
8315
        b = m[i + 1] / d;
8316
        s = a * a + b * b;
8317
        if (s > 9) {
8318
          s = d * 3 / Math.sqrt(s);
8319
          m[i] = s * a;
8320
          m[i + 1] = s * b;
8321
        }
8322
      }
8323
    }
8324
    i = -1;
8325
    while (++i <= j) {
8326
      s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
8327
      tangents.push([ s || 0, m[i] * s || 0 ]);
8328
    }
8329
    return tangents;
8330
  }
8331
  function d3_svg_lineMonotone(points) {
8332
    return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
8333
  }
8334
  d3.svg.line.radial = function() {
8335
    var line = d3_svg_line(d3_svg_lineRadial);
8336
    line.radius = line.x, delete line.x;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8337
    line.angle = line.y, delete line.y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8338
    return line;
8339
  };
8340
  function d3_svg_lineRadial(points) {
8341
    var point, i = -1, n = points.length, r, a;
8342
    while (++i < n) {
8343
      point = points[i];
8344
      r = point[0];
8345
      a = point[1] - halfπ;
8346
      point[0] = r * Math.cos(a);
8347
      point[1] = r * Math.sin(a);
8348
    }
8349
    return points;
8350
  }
8351
  function d3_svg_area(projection) {
8352
    var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
8353
    function area(data) {
8354
      var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
8355
        return x;
8356
      } : d3_functor(x1), fy1 = y0 === y1 ? function() {
8357
        return y;
8358
      } : d3_functor(y1), x, y;
8359
      function segment() {
8360
        segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
8361
      }
8362
      while (++i < n) {
8363
        if (defined.call(this, d = data[i], i)) {
8364
          points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
8365
          points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
8366
        } else if (points0.length) {
8367
          segment();
8368
          points0 = [];
8369
          points1 = [];
8370
        }
8371
      }
8372
      if (points0.length) segment();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8373
      return segments.length ? segments.join("") : null;
8374
    }
8375
    area.x = function(_) {
8376
      if (!arguments.length) return x1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8377
      x0 = x1 = _;
8378
      return area;
8379
    };
8380
    area.x0 = function(_) {
8381
      if (!arguments.length) return x0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8382
      x0 = _;
8383
      return area;
8384
    };
8385
    area.x1 = function(_) {
8386
      if (!arguments.length) return x1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8387
      x1 = _;
8388
      return area;
8389
    };
8390
    area.y = function(_) {
8391
      if (!arguments.length) return y1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8392
      y0 = y1 = _;
8393
      return area;
8394
    };
8395
    area.y0 = function(_) {
8396
      if (!arguments.length) return y0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8397
      y0 = _;
8398
      return area;
8399
    };
8400
    area.y1 = function(_) {
8401
      if (!arguments.length) return y1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8402
      y1 = _;
8403
      return area;
8404
    };
8405
    area.defined = function(_) {
8406
      if (!arguments.length) return defined;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8407
      defined = _;
8408
      return area;
8409
    };
8410
    area.interpolate = function(_) {
8411
      if (!arguments.length) return interpolateKey;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8412
      if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8413
      interpolateReverse = interpolate.reverse || interpolate;
8414
      L = interpolate.closed ? "M" : "L";
8415
      return area;
8416
    };
8417
    area.tension = function(_) {
8418
      if (!arguments.length) return tension;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8419
      tension = _;
8420
      return area;
8421
    };
8422
    return area;
8423
  }
8424
  d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
8425
  d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
8426
  d3.svg.area = function() {
8427
    return d3_svg_area(d3_identity);
8428
  };
8429
  d3.svg.area.radial = function() {
8430
    var area = d3_svg_area(d3_svg_lineRadial);
8431
    area.radius = area.x, delete area.x;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8432
    area.innerRadius = area.x0, delete area.x0;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8433
    area.outerRadius = area.x1, delete area.x1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8434
    area.angle = area.y, delete area.y;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8435
    area.startAngle = area.y0, delete area.y0;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8436
    area.endAngle = area.y1, delete area.y1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8437
    return area;
8438
  };
8439
  d3.svg.chord = function() {
8440
    var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
8441
    function chord(d, i) {
8442
      var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
8443
      return "M" + s.p0 + arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t) ? curve(s.r, s.p1, s.r, s.p0) : curve(s.r, s.p1, t.r, t.p0) + arc(t.r, t.p1, t.a1 - t.a0) + curve(t.r, t.p1, s.r, s.p0)) + "Z";
8444
    }
8445
    function subgroup(self, f, d, i) {
8446
      var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
8447
      return {
8448
        r: r,
8449
        a0: a0,
8450
        a1: a1,
8451
        p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
8452
        p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
8453
      };
8454
    }
8455
    function equals(a, b) {
8456
      return a.a0 == b.a0 && a.a1 == b.a1;
8457
    }
8458
    function arc(r, p, a) {
8459
      return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
8460
    }
8461
    function curve(r0, p0, r1, p1) {
8462
      return "Q 0,0 " + p1;
8463
    }
8464
    chord.radius = function(v) {
8465
      if (!arguments.length) return radius;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8466
      radius = d3_functor(v);
8467
      return chord;
8468
    };
8469
    chord.source = function(v) {
8470
      if (!arguments.length) return source;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8471
      source = d3_functor(v);
8472
      return chord;
8473
    };
8474
    chord.target = function(v) {
8475
      if (!arguments.length) return target;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8476
      target = d3_functor(v);
8477
      return chord;
8478
    };
8479
    chord.startAngle = function(v) {
8480
      if (!arguments.length) return startAngle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8481
      startAngle = d3_functor(v);
8482
      return chord;
8483
    };
8484
    chord.endAngle = function(v) {
8485
      if (!arguments.length) return endAngle;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8486
      endAngle = d3_functor(v);
8487
      return chord;
8488
    };
8489
    return chord;
8490
  };
8491
  function d3_svg_chordRadius(d) {
8492
    return d.radius;
8493
  }
8494
  d3.svg.diagonal = function() {
8495
    var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
8496
    function diagonal(d, i) {
8497
      var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
8498
        x: p0.x,
8499
        y: m
8500
      }, {
8501
        x: p3.x,
8502
        y: m
8503
      }, p3 ];
8504
      p = p.map(projection);
8505
      return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
8506
    }
8507
    diagonal.source = function(x) {
8508
      if (!arguments.length) return source;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8509
      source = d3_functor(x);
8510
      return diagonal;
8511
    };
8512
    diagonal.target = function(x) {
8513
      if (!arguments.length) return target;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8514
      target = d3_functor(x);
8515
      return diagonal;
8516
    };
8517
    diagonal.projection = function(x) {
8518
      if (!arguments.length) return projection;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8519
      projection = x;
8520
      return diagonal;
8521
    };
8522
    return diagonal;
8523
  };
8524
  function d3_svg_diagonalProjection(d) {
8525
    return [ d.x, d.y ];
8526
  }
8527
  d3.svg.diagonal.radial = function() {
8528
    var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
8529
    diagonal.projection = function(x) {
8530
      return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
8531
    };
8532
    return diagonal;
8533
  };
8534
  function d3_svg_diagonalRadialProjection(projection) {
8535
    return function() {
8536
      var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
8537
      return [ r * Math.cos(a), r * Math.sin(a) ];
8538
    };
8539
  }
8540
  d3.svg.symbol = function() {
8541
    var type = d3_svg_symbolType, size = d3_svg_symbolSize;
8542
    function symbol(d, i) {
8543
      return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
8544
    }
8545
    symbol.type = function(x) {
8546
      if (!arguments.length) return type;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8547
      type = d3_functor(x);
8548
      return symbol;
8549
    };
8550
    symbol.size = function(x) {
8551
      if (!arguments.length) return size;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8552
      size = d3_functor(x);
8553
      return symbol;
8554
    };
8555
    return symbol;
8556
  };
8557
  function d3_svg_symbolSize() {
8558
    return 64;
8559
  }
8560
  function d3_svg_symbolType() {
8561
    return "circle";
8562
  }
8563
  function d3_svg_symbolCircle(size) {
8564
    var r = Math.sqrt(size / π);
8565
    return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
8566
  }
8567
  var d3_svg_symbols = d3.map({
8568
    circle: d3_svg_symbolCircle,
8569
    cross: function(size) {
8570
      var r = Math.sqrt(size / 5) / 2;
8571
      return "M" + -3 * r + "," + -r + "H" + -r + "V" + -3 * r + "H" + r + "V" + -r + "H" + 3 * r + "V" + r + "H" + r + "V" + 3 * r + "H" + -r + "V" + r + "H" + -3 * r + "Z";
8572
    },
8573
    diamond: function(size) {
8574
      var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
8575
      return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
8576
    },
8577
    square: function(size) {
8578
      var r = Math.sqrt(size) / 2;
8579
      return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
8580
    },
8581
    "triangle-down": function(size) {
8582
      var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8583
      return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
8584
    },
8585
    "triangle-up": function(size) {
8586
      var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8587
      return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
8588
    }
8589
  });
8590
  d3.svg.symbolTypes = d3_svg_symbols.keys();
8591
  var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
8592
  d3_selectionPrototype.transition = function(name) {
8593
    var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
8594
      time: Date.now(),
8595
      ease: d3_ease_cubicInOut,
8596
      delay: 0,
8597
      duration: 250
8598
    };
8599
    for (var j = -1, m = this.length; ++j < m; ) {
8600
      subgroups.push(subgroup = []);
8601
      for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8602
        if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8603
        subgroup.push(node);
8604
      }
8605
    }
8606
    return d3_transition(subgroups, ns, id);
8607
  };
8608
  d3_selectionPrototype.interrupt = function(name) {
8609
    return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
8610
  };
8611
  var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
8612
  function d3_selection_interruptNS(ns) {
8613
    return function() {
8614
      var lock, active;
8615
      if ((lock = this[ns]) && (active = lock[lock.active])) {
8616
        if (--lock.count) delete lock[lock.active]; else delete this[ns];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8617
        lock.active += .5;
8618
        active.event && active.event.interrupt.call(this, this.__data__, active.index);
8619
      }
8620
    };
8621
  }
8622
  function d3_transition(groups, ns, id) {
8623
    d3_subclass(groups, d3_transitionPrototype);
8624
    groups.namespace = ns;
8625
    groups.id = id;
8626
    return groups;
8627
  }
8628
  var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
8629
  d3_transitionPrototype.call = d3_selectionPrototype.call;
8630
  d3_transitionPrototype.empty = d3_selectionPrototype.empty;
8631
  d3_transitionPrototype.node = d3_selectionPrototype.node;
8632
  d3_transitionPrototype.size = d3_selectionPrototype.size;
8633
  d3.transition = function(selection, name) {
8634
    return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
8635
  };
8636
  d3.transition.prototype = d3_transitionPrototype;
8637
  d3_transitionPrototype.select = function(selector) {
8638
    var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
8639
    selector = d3_selection_selector(selector);
8640
    for (var j = -1, m = this.length; ++j < m; ) {
8641
      subgroups.push(subgroup = []);
8642
      for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8643
        if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
8644
          if ("__data__" in node) subnode.__data__ = node.__data__;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8645
          d3_transitionNode(subnode, i, ns, id, node[ns][id]);
8646
          subgroup.push(subnode);
8647
        } else {
8648
          subgroup.push(null);
8649
        }
8650
      }
8651
    }
8652
    return d3_transition(subgroups, ns, id);
8653
  };
8654
  d3_transitionPrototype.selectAll = function(selector) {
8655
    var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
8656
    selector = d3_selection_selectorAll(selector);
8657
    for (var j = -1, m = this.length; ++j < m; ) {
8658
      for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8659
        if (node = group[i]) {
8660
          transition = node[ns][id];
8661
          subnodes = selector.call(node, node.__data__, i, j);
8662
          subgroups.push(subgroup = []);
8663
          for (var k = -1, o = subnodes.length; ++k < o; ) {
8664
            if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8665
            subgroup.push(subnode);
8666
          }
8667
        }
8668
      }
8669
    }
8670
    return d3_transition(subgroups, ns, id);
8671
  };
8672
  d3_transitionPrototype.filter = function(filter) {
8673
    var subgroups = [], subgroup, group, node;
8674
    if (typeof filter !== "function") filter = d3_selection_filter(filter);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8675
    for (var j = 0, m = this.length; j < m; j++) {
8676
      subgroups.push(subgroup = []);
8677
      for (var group = this[j], i = 0, n = group.length; i < n; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable group already seems to be declared on line 8673. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
8678
        if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
8679
          subgroup.push(node);
8680
        }
8681
      }
8682
    }
8683
    return d3_transition(subgroups, this.namespace, this.id);
8684
  };
8685
  d3_transitionPrototype.tween = function(name, tween) {
8686
    var id = this.id, ns = this.namespace;
8687
    if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8688
    return d3_selection_each(this, tween == null ? function(node) {
8689
      node[ns][id].tween.remove(name);
8690
    } : function(node) {
8691
      node[ns][id].tween.set(name, tween);
8692
    });
8693
  };
8694
  function d3_transition_tween(groups, name, value, tween) {
8695
    var id = groups.id, ns = groups.namespace;
8696
    return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
8697
      node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
8698
    } : (value = tween(value), function(node) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8699
      node[ns][id].tween.set(name, value);
8700
    }));
8701
  }
8702
  d3_transitionPrototype.attr = function(nameNS, value) {
8703
    if (arguments.length < 2) {
8704
      for (value in nameNS) this.attr(value, nameNS[value]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8705
      return this;
8706
    }
8707
    var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
8708
    function attrNull() {
8709
      this.removeAttribute(name);
8710
    }
8711
    function attrNullNS() {
8712
      this.removeAttributeNS(name.space, name.local);
8713
    }
8714
    function attrTween(b) {
8715
      return b == null ? attrNull : (b += "", function() {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8716
        var a = this.getAttribute(name), i;
8717
        return a !== b && (i = interpolate(a, b), function(t) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8718
          this.setAttribute(name, i(t));
8719
        });
8720
      });
8721
    }
8722
    function attrTweenNS(b) {
8723
      return b == null ? attrNullNS : (b += "", function() {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8724
        var a = this.getAttributeNS(name.space, name.local), i;
8725
        return a !== b && (i = interpolate(a, b), function(t) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8726
          this.setAttributeNS(name.space, name.local, i(t));
8727
        });
8728
      });
8729
    }
8730
    return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
8731
  };
8732
  d3_transitionPrototype.attrTween = function(nameNS, tween) {
8733
    var name = d3.ns.qualify(nameNS);
8734
    function attrTween(d, i) {
8735
      var f = tween.call(this, d, i, this.getAttribute(name));
8736
      return f && function(t) {
8737
        this.setAttribute(name, f(t));
8738
      };
8739
    }
8740
    function attrTweenNS(d, i) {
8741
      var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
8742
      return f && function(t) {
8743
        this.setAttributeNS(name.space, name.local, f(t));
8744
      };
8745
    }
8746
    return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
8747
  };
8748
  d3_transitionPrototype.style = function(name, value, priority) {
8749
    var n = arguments.length;
8750
    if (n < 3) {
8751
      if (typeof name !== "string") {
8752
        if (n < 2) value = "";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8753
        for (priority in name) this.style(priority, name[priority], value);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8754
        return this;
8755
      }
8756
      priority = "";
8757
    }
8758
    function styleNull() {
8759
      this.style.removeProperty(name);
8760
    }
8761
    function styleString(b) {
8762
      return b == null ? styleNull : (b += "", function() {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8763
        var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
8764
        return a !== b && (i = d3_interpolate(a, b), function(t) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8765
          this.style.setProperty(name, i(t), priority);
8766
        });
8767
      });
8768
    }
8769
    return d3_transition_tween(this, "style." + name, value, styleString);
8770
  };
8771
  d3_transitionPrototype.styleTween = function(name, tween, priority) {
8772
    if (arguments.length < 3) priority = "";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8773
    function styleTween(d, i) {
8774
      var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
8775
      return f && function(t) {
8776
        this.style.setProperty(name, f(t), priority);
8777
      };
8778
    }
8779
    return this.tween("style." + name, styleTween);
8780
  };
8781
  d3_transitionPrototype.text = function(value) {
8782
    return d3_transition_tween(this, "text", value, d3_transition_text);
8783
  };
8784
  function d3_transition_text(b) {
8785
    if (b == null) b = "";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8786
    return function() {
8787
      this.textContent = b;
8788
    };
8789
  }
8790
  d3_transitionPrototype.remove = function() {
8791
    var ns = this.namespace;
8792
    return this.each("end.transition", function() {
8793
      var p;
8794
      if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8795
    });
8796
  };
8797
  d3_transitionPrototype.ease = function(value) {
8798
    var id = this.id, ns = this.namespace;
8799
    if (arguments.length < 1) return this.node()[ns][id].ease;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8800
    if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8801
    return d3_selection_each(this, function(node) {
8802
      node[ns][id].ease = value;
8803
    });
8804
  };
8805
  d3_transitionPrototype.delay = function(value) {
8806
    var id = this.id, ns = this.namespace;
8807
    if (arguments.length < 1) return this.node()[ns][id].delay;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8808
    return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8809
      node[ns][id].delay = +value.call(node, node.__data__, i, j);
8810
    } : (value = +value, function(node) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8811
      node[ns][id].delay = value;
8812
    }));
8813
  };
8814
  d3_transitionPrototype.duration = function(value) {
8815
    var id = this.id, ns = this.namespace;
8816
    if (arguments.length < 1) return this.node()[ns][id].duration;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8817
    return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8818
      node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
8819
    } : (value = Math.max(1, value), function(node) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8820
      node[ns][id].duration = value;
8821
    }));
8822
  };
8823
  d3_transitionPrototype.each = function(type, listener) {
8824
    var id = this.id, ns = this.namespace;
8825
    if (arguments.length < 2) {
8826
      var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
8827
      try {
8828
        d3_transitionInheritId = id;
8829
        d3_selection_each(this, function(node, i, j) {
8830
          d3_transitionInherit = node[ns][id];
8831
          type.call(node, node.__data__, i, j);
8832
        });
8833
      } finally {
8834
        d3_transitionInherit = inherit;
8835
        d3_transitionInheritId = inheritId;
8836
      }
8837
    } else {
8838
      d3_selection_each(this, function(node) {
8839
        var transition = node[ns][id];
8840
        (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
8841
      });
8842
    }
8843
    return this;
8844
  };
8845
  d3_transitionPrototype.transition = function() {
8846
    var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
8847
    for (var j = 0, m = this.length; j < m; j++) {
8848
      subgroups.push(subgroup = []);
8849
      for (var group = this[j], i = 0, n = group.length; i < n; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable group already seems to be declared on line 8846. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
8850
        if (node = group[i]) {
8851
          transition = node[ns][id0];
8852
          d3_transitionNode(node, i, ns, id1, {
8853
            time: transition.time,
8854
            ease: transition.ease,
8855
            delay: transition.delay + transition.duration,
8856
            duration: transition.duration
8857
          });
8858
        }
8859
        subgroup.push(node);
8860
      }
8861
    }
8862
    return d3_transition(subgroups, ns, id1);
8863
  };
8864
  function d3_transitionNamespace(name) {
8865
    return name == null ? "__transition__" : "__transition_" + name + "__";
8866
  }
8867
  function d3_transitionNode(node, i, ns, id, inherit) {
8868
    var lock = node[ns] || (node[ns] = {
8869
      active: 0,
8870
      count: 0
8871
    }), transition = lock[id];
8872
    if (!transition) {
8873
      var time = inherit.time;
8874
      transition = lock[id] = {
8875
        tween: new d3_Map(),
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_Map should be capitalized.
Loading history...
8876
        time: time,
8877
        delay: inherit.delay,
8878
        duration: inherit.duration,
8879
        ease: inherit.ease,
8880
        index: i
8881
      };
8882
      inherit = null;
0 ignored issues
show
Unused Code introduced by
The assignment to inherit seems to be never used. If you intend to free memory here, this is not necessary since the variable leaves the scope anyway.
Loading history...
8883
      ++lock.count;
8884
      d3.timer(function(elapsed) {
8885
        var delay = transition.delay, duration, ease, timer = d3_timer_active, tweened = [];
8886
        timer.t = delay + time;
8887
        if (delay <= elapsed) return start(elapsed - delay);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8888
        timer.c = start;
8889
        function start(elapsed) {
8890
          if (lock.active > id) return stop();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8891
          var active = lock[lock.active];
8892
          if (active) {
8893
            --lock.count;
8894
            delete lock[lock.active];
8895
            active.event && active.event.interrupt.call(node, node.__data__, active.index);
8896
          }
8897
          lock.active = id;
8898
          transition.event && transition.event.start.call(node, node.__data__, i);
8899
          transition.tween.forEach(function(key, value) {
8900
            if (value = value.call(node, node.__data__, i)) {
8901
              tweened.push(value);
8902
            }
8903
          });
8904
          ease = transition.ease;
8905
          duration = transition.duration;
8906
          d3.timer(function() {
8907
            timer.c = tick(elapsed || 1) ? d3_true : tick;
8908
            return 1;
8909
          }, 0, time);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
8910
        }
8911
        function tick(elapsed) {
8912
          if (lock.active !== id) return 1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8913
          var t = elapsed / duration, e = ease(t), n = tweened.length;
8914
          while (n > 0) {
8915
            tweened[--n].call(node, e);
8916
          }
8917
          if (t >= 1) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if t >= 1 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
8918
            transition.event && transition.event.end.call(node, node.__data__, i);
8919
            return stop();
8920
          }
8921
        }
8922
        function stop() {
8923
          if (--lock.count) delete lock[id]; else delete node[ns];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8924
          return 1;
8925
        }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
8926
      }, 0, time);
8927
    }
8928
  }
8929
  d3.svg.axis = function() {
8930
    var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
8931
    function axis(g) {
8932
      g.each(function() {
8933
        var g = d3.select(this);
8934
        var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
8935
        var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
8936
        var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"), 
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8937
        d3.transition(path));
8938
        tickEnter.append("line");
8939
        tickEnter.append("text");
8940
        var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
8941
        if (orient === "bottom" || orient === "top") {
8942
          tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8943
          text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
8944
          pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
8945
        } else {
8946
          tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
8947
          text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
8948
          pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
8949
        }
8950
        lineEnter.attr(y2, sign * innerTickSize);
8951
        textEnter.attr(y1, sign * tickSpacing);
8952
        lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
8953
        textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
8954
        if (scale1.rangeBand) {
8955
          var x = scale1, dx = x.rangeBand() / 2;
8956
          scale0 = scale1 = function(d) {
8957
            return x(d) + dx;
8958
          };
8959
        } else if (scale0.rangeBand) {
8960
          scale0 = scale1;
8961
        } else {
8962
          tickExit.call(tickTransform, scale1, scale0);
8963
        }
8964
        tickEnter.call(tickTransform, scale0, scale1);
8965
        tickUpdate.call(tickTransform, scale1, scale1);
8966
      });
8967
    }
8968
    axis.scale = function(x) {
8969
      if (!arguments.length) return scale;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8970
      scale = x;
8971
      return axis;
8972
    };
8973
    axis.orient = function(x) {
8974
      if (!arguments.length) return orient;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8975
      orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
8976
      return axis;
8977
    };
8978
    axis.ticks = function() {
8979
      if (!arguments.length) return tickArguments_;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8980
      tickArguments_ = arguments;
8981
      return axis;
8982
    };
8983
    axis.tickValues = function(x) {
8984
      if (!arguments.length) return tickValues;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8985
      tickValues = x;
8986
      return axis;
8987
    };
8988
    axis.tickFormat = function(x) {
8989
      if (!arguments.length) return tickFormat_;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8990
      tickFormat_ = x;
8991
      return axis;
8992
    };
8993
    axis.tickSize = function(x) {
8994
      var n = arguments.length;
8995
      if (!n) return innerTickSize;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8996
      innerTickSize = +x;
8997
      outerTickSize = +arguments[n - 1];
8998
      return axis;
8999
    };
9000
    axis.innerTickSize = function(x) {
9001
      if (!arguments.length) return innerTickSize;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9002
      innerTickSize = +x;
9003
      return axis;
9004
    };
9005
    axis.outerTickSize = function(x) {
9006
      if (!arguments.length) return outerTickSize;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9007
      outerTickSize = +x;
9008
      return axis;
9009
    };
9010
    axis.tickPadding = function(x) {
9011
      if (!arguments.length) return tickPadding;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9012
      tickPadding = +x;
9013
      return axis;
9014
    };
9015
    axis.tickSubdivide = function() {
9016
      return arguments.length && axis;
9017
    };
9018
    return axis;
9019
  };
9020
  var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
9021
    top: 1,
9022
    right: 1,
9023
    bottom: 1,
9024
    left: 1
9025
  };
9026
  function d3_svg_axisX(selection, x0, x1) {
9027
    selection.attr("transform", function(d) {
9028
      var v0 = x0(d);
9029
      return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
9030
    });
9031
  }
9032
  function d3_svg_axisY(selection, y0, y1) {
9033
    selection.attr("transform", function(d) {
9034
      var v0 = y0(d);
9035
      return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
9036
    });
9037
  }
9038
  d3.svg.brush = function() {
9039
    var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0];
9040
    function brush(g) {
9041
      g.each(function() {
9042
        var g = d3.select(this).style("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
9043
        var background = g.selectAll(".background").data([ 0 ]);
9044
        background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
9045
        g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
9046
        var resize = g.selectAll(".resize").data(resizes, d3_identity);
9047
        resize.exit().remove();
9048
        resize.enter().append("g").attr("class", function(d) {
9049
          return "resize " + d;
9050
        }).style("cursor", function(d) {
9051
          return d3_svg_brushCursor[d];
9052
        }).append("rect").attr("x", function(d) {
9053
          return /[ew]$/.test(d) ? -3 : null;
9054
        }).attr("y", function(d) {
9055
          return /^[ns]/.test(d) ? -3 : null;
9056
        }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
9057
        resize.style("display", brush.empty() ? "none" : null);
9058
        var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
9059
        if (x) {
9060
          range = d3_scaleRange(x);
9061
          backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
9062
          redrawX(gUpdate);
9063
        }
9064
        if (y) {
9065
          range = d3_scaleRange(y);
9066
          backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
9067
          redrawY(gUpdate);
9068
        }
9069
        redraw(gUpdate);
9070
      });
9071
    }
9072
    brush.event = function(g) {
9073
      g.each(function() {
9074
        var event_ = event.of(this, arguments), extent1 = {
9075
          x: xExtent,
9076
          y: yExtent,
9077
          i: xExtentDomain,
9078
          j: yExtentDomain
9079
        }, extent0 = this.__chart__ || extent1;
9080
        this.__chart__ = extent1;
9081
        if (d3_transitionInheritId) {
9082
          d3.select(this).transition().each("start.brush", function() {
9083
            xExtentDomain = extent0.i;
9084
            yExtentDomain = extent0.j;
9085
            xExtent = extent0.x;
9086
            yExtent = extent0.y;
9087
            event_({
9088
              type: "brushstart"
9089
            });
9090
          }).tween("brush:brush", function() {
9091
            var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
9092
            xExtentDomain = yExtentDomain = null;
9093
            return function(t) {
9094
              xExtent = extent1.x = xi(t);
9095
              yExtent = extent1.y = yi(t);
9096
              event_({
9097
                type: "brush",
9098
                mode: "resize"
9099
              });
9100
            };
9101
          }).each("end.brush", function() {
9102
            xExtentDomain = extent1.i;
9103
            yExtentDomain = extent1.j;
9104
            event_({
9105
              type: "brush",
9106
              mode: "resize"
9107
            });
9108
            event_({
9109
              type: "brushend"
9110
            });
9111
          });
9112
        } else {
9113
          event_({
9114
            type: "brushstart"
9115
          });
9116
          event_({
9117
            type: "brush",
9118
            mode: "resize"
9119
          });
9120
          event_({
9121
            type: "brushend"
9122
          });
9123
        }
9124
      });
9125
    };
9126
    function redraw(g) {
9127
      g.selectAll(".resize").attr("transform", function(d) {
9128
        return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
9129
      });
9130
    }
9131
    function redrawX(g) {
9132
      g.select(".extent").attr("x", xExtent[0]);
9133
      g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
9134
    }
9135
    function redrawY(g) {
9136
      g.select(".extent").attr("y", yExtent[0]);
9137
      g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
9138
    }
9139
    function brushstart() {
9140
      var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;
9141
      var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
9142
      if (d3.event.changedTouches) {
9143
        w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
9144
      } else {
9145
        w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
9146
      }
9147
      g.interrupt().selectAll("*").interrupt();
9148
      if (dragging) {
9149
        origin[0] = xExtent[0] - origin[0];
9150
        origin[1] = yExtent[0] - origin[1];
9151
      } else if (resizing) {
9152
        var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
9153
        offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
9154
        origin[0] = xExtent[ex];
9155
        origin[1] = yExtent[ey];
9156
      } else if (d3.event.altKey) center = origin.slice();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9157
      g.style("pointer-events", "none").selectAll(".resize").style("display", null);
9158
      d3.select("body").style("cursor", eventTarget.style("cursor"));
9159
      event_({
9160
        type: "brushstart"
9161
      });
9162
      brushmove();
9163
      function keydown() {
9164
        if (d3.event.keyCode == 32) {
9165
          if (!dragging) {
9166
            center = null;
9167
            origin[0] -= xExtent[1];
9168
            origin[1] -= yExtent[1];
9169
            dragging = 2;
9170
          }
9171
          d3_eventPreventDefault();
9172
        }
9173
      }
9174
      function keyup() {
9175
        if (d3.event.keyCode == 32 && dragging == 2) {
9176
          origin[0] += xExtent[1];
9177
          origin[1] += yExtent[1];
9178
          dragging = 0;
9179
          d3_eventPreventDefault();
9180
        }
9181
      }
9182
      function brushmove() {
9183
        var point = d3.mouse(target), moved = false;
9184
        if (offset) {
9185
          point[0] += offset[0];
9186
          point[1] += offset[1];
9187
        }
9188
        if (!dragging) {
9189
          if (d3.event.altKey) {
9190
            if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9191
            origin[0] = xExtent[+(point[0] < center[0])];
9192
            origin[1] = yExtent[+(point[1] < center[1])];
9193
          } else center = null;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9194
        }
9195
        if (resizingX && move1(point, x, 0)) {
9196
          redrawX(g);
9197
          moved = true;
9198
        }
9199
        if (resizingY && move1(point, y, 1)) {
9200
          redrawY(g);
9201
          moved = true;
9202
        }
9203
        if (moved) {
9204
          redraw(g);
9205
          event_({
9206
            type: "brush",
9207
            mode: dragging ? "move" : "resize"
9208
          });
9209
        }
9210
      }
9211
      function move1(point, scale, i) {
9212
        var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max;
9213
        if (dragging) {
9214
          r0 -= position;
9215
          r1 -= size + position;
9216
        }
9217
        min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
9218
        if (dragging) {
9219
          max = (min += position) + size;
9220
        } else {
9221
          if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9222
          if (position < min) {
9223
            max = min;
9224
            min = position;
9225
          } else {
9226
            max = position;
9227
          }
9228
        }
9229
        if (extent[0] != min || extent[1] != max) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if extent.0 != min || extent.1 != max is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
9230
          if (i) yExtentDomain = null; else xExtentDomain = null;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9231
          extent[0] = min;
9232
          extent[1] = max;
9233
          return true;
9234
        }
9235
      }
9236
      function brushend() {
9237
        brushmove();
9238
        g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
9239
        d3.select("body").style("cursor", null);
9240
        w.on("mousemove.brush", null).on("mouseup.brush", null).on("touchmove.brush", null).on("touchend.brush", null).on("keydown.brush", null).on("keyup.brush", null);
9241
        dragRestore();
9242
        event_({
9243
          type: "brushend"
9244
        });
9245
      }
9246
    }
9247
    brush.x = function(z) {
9248
      if (!arguments.length) return x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9249
      x = z;
9250
      resizes = d3_svg_brushResizes[!x << 1 | !y];
9251
      return brush;
9252
    };
9253
    brush.y = function(z) {
9254
      if (!arguments.length) return y;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9255
      y = z;
9256
      resizes = d3_svg_brushResizes[!x << 1 | !y];
9257
      return brush;
9258
    };
9259
    brush.clamp = function(z) {
9260
      if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9261
      if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9262
      return brush;
9263
    };
9264
    brush.extent = function(z) {
9265
      var x0, x1, y0, y1, t;
9266
      if (!arguments.length) {
9267
        if (x) {
9268
          if (xExtentDomain) {
9269
            x0 = xExtentDomain[0], x1 = xExtentDomain[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9270
          } else {
9271
            x0 = xExtent[0], x1 = xExtent[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9272
            if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9273
            if (x1 < x0) t = x0, x0 = x1, x1 = t;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9274
          }
9275
        }
9276
        if (y) {
9277
          if (yExtentDomain) {
9278
            y0 = yExtentDomain[0], y1 = yExtentDomain[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9279
          } else {
9280
            y0 = yExtent[0], y1 = yExtent[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9281
            if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9282
            if (y1 < y0) t = y0, y0 = y1, y1 = t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9283
          }
9284
        }
9285
        return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
0 ignored issues
show
Bug introduced by
The variable y1 does not seem to be initialized in case y on line 9276 is false. Are you sure this can never be the case?
Loading history...
Bug introduced by
The variable y0 does not seem to be initialized in case y on line 9276 is false. Are you sure this can never be the case?
Loading history...
Bug introduced by
The variable x0 does not seem to be initialized in case x on line 9267 is false. Are you sure this can never be the case?
Loading history...
Bug introduced by
The variable x1 does not seem to be initialized in case x on line 9267 is false. Are you sure this can never be the case?
Loading history...
9286
      }
9287
      if (x) {
9288
        x0 = z[0], x1 = z[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9289
        if (y) x0 = x0[0], x1 = x1[0];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9290
        xExtentDomain = [ x0, x1 ];
9291
        if (x.invert) x0 = x(x0), x1 = x(x1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9292
        if (x1 < x0) t = x0, x0 = x1, x1 = t;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9293
        if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9294
      }
9295
      if (y) {
9296
        y0 = z[0], y1 = z[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9297
        if (x) y0 = y0[1], y1 = y1[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9298
        yExtentDomain = [ y0, y1 ];
9299
        if (y.invert) y0 = y(y0), y1 = y(y1);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9300
        if (y1 < y0) t = y0, y0 = y1, y1 = t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9301
        if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9302
      }
9303
      return brush;
9304
    };
9305
    brush.clear = function() {
9306
      if (!brush.empty()) {
9307
        xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9308
        xExtentDomain = yExtentDomain = null;
9309
      }
9310
      return brush;
9311
    };
9312
    brush.empty = function() {
9313
      return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
9314
    };
9315
    return d3.rebind(brush, event, "on");
9316
  };
9317
  var d3_svg_brushCursor = {
9318
    n: "ns-resize",
9319
    e: "ew-resize",
9320
    s: "ns-resize",
9321
    w: "ew-resize",
9322
    nw: "nwse-resize",
9323
    ne: "nesw-resize",
9324
    se: "nwse-resize",
9325
    sw: "nesw-resize"
9326
  };
9327
  var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
9328
  var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
9329
  var d3_time_formatUtc = d3_time_format.utc;
9330
  var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
9331
  d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
9332
  function d3_time_formatIsoNative(date) {
9333
    return date.toISOString();
9334
  }
9335
  d3_time_formatIsoNative.parse = function(string) {
9336
    var date = new Date(string);
9337
    return isNaN(date) ? null : date;
9338
  };
9339
  d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
9340
  d3_time.second = d3_time_interval(function(date) {
9341
    return new d3_date(Math.floor(date / 1e3) * 1e3);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_date should be capitalized.
Loading history...
9342
  }, function(date, offset) {
9343
    date.setTime(date.getTime() + Math.floor(offset) * 1e3);
9344
  }, function(date) {
9345
    return date.getSeconds();
9346
  });
9347
  d3_time.seconds = d3_time.second.range;
9348
  d3_time.seconds.utc = d3_time.second.utc.range;
9349
  d3_time.minute = d3_time_interval(function(date) {
9350
    return new d3_date(Math.floor(date / 6e4) * 6e4);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_date should be capitalized.
Loading history...
9351
  }, function(date, offset) {
9352
    date.setTime(date.getTime() + Math.floor(offset) * 6e4);
9353
  }, function(date) {
9354
    return date.getMinutes();
9355
  });
9356
  d3_time.minutes = d3_time.minute.range;
9357
  d3_time.minutes.utc = d3_time.minute.utc.range;
9358
  d3_time.hour = d3_time_interval(function(date) {
9359
    var timezone = date.getTimezoneOffset() / 60;
9360
    return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like d3_date should be capitalized.
Loading history...
9361
  }, function(date, offset) {
9362
    date.setTime(date.getTime() + Math.floor(offset) * 36e5);
9363
  }, function(date) {
9364
    return date.getHours();
9365
  });
9366
  d3_time.hours = d3_time.hour.range;
9367
  d3_time.hours.utc = d3_time.hour.utc.range;
9368
  d3_time.month = d3_time_interval(function(date) {
9369
    date = d3_time.day(date);
9370
    date.setDate(1);
9371
    return date;
9372
  }, function(date, offset) {
9373
    date.setMonth(date.getMonth() + offset);
9374
  }, function(date) {
9375
    return date.getMonth();
9376
  });
9377
  d3_time.months = d3_time.month.range;
9378
  d3_time.months.utc = d3_time.month.utc.range;
9379
  function d3_time_scale(linear, methods, format) {
9380
    function scale(x) {
9381
      return linear(x);
9382
    }
9383
    scale.invert = function(x) {
9384
      return d3_time_scaleDate(linear.invert(x));
9385
    };
9386
    scale.domain = function(x) {
9387
      if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9388
      linear.domain(x);
9389
      return scale;
9390
    };
9391
    function tickMethod(extent, count) {
9392
      var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
9393
      return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
9394
        return d / 31536e6;
9395
      }), count)[2] ] : !i ? [ d3_time_scaleMilliseconds, d3_scale_linearTickRange(extent, count)[2] ] : methods[target / d3_time_scaleSteps[i - 1] < d3_time_scaleSteps[i] / target ? i - 1 : i];
9396
    }
9397
    scale.nice = function(interval, skip) {
9398
      var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
9399
      if (method) interval = method[0], skip = method[1];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9400
      function skipped(date) {
9401
        return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
9402
      }
9403
      return scale.domain(d3_scale_nice(domain, skip > 1 ? {
9404
        floor: function(date) {
9405
          while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9406
          return date;
9407
        },
9408
        ceil: function(date) {
9409
          while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9410
          return date;
9411
        }
9412
      } : interval));
9413
    };
9414
    scale.ticks = function(interval, skip) {
9415
      var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
9416
        range: interval
9417
      }, skip ];
9418
      if (method) interval = method[0], skip = method[1];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9419
      return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
9420
    };
9421
    scale.tickFormat = function() {
9422
      return format;
9423
    };
9424
    scale.copy = function() {
9425
      return d3_time_scale(linear.copy(), methods, format);
9426
    };
9427
    return d3_scale_linearRebind(scale, linear);
9428
  }
9429
  function d3_time_scaleDate(t) {
9430
    return new Date(t);
9431
  }
9432
  var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
9433
  var d3_time_scaleLocalMethods = [ [ d3_time.second, 1 ], [ d3_time.second, 5 ], [ d3_time.second, 15 ], [ d3_time.second, 30 ], [ d3_time.minute, 1 ], [ d3_time.minute, 5 ], [ d3_time.minute, 15 ], [ d3_time.minute, 30 ], [ d3_time.hour, 1 ], [ d3_time.hour, 3 ], [ d3_time.hour, 6 ], [ d3_time.hour, 12 ], [ d3_time.day, 1 ], [ d3_time.day, 2 ], [ d3_time.week, 1 ], [ d3_time.month, 1 ], [ d3_time.month, 3 ], [ d3_time.year, 1 ] ];
9434
  var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
9435
    return d.getMilliseconds();
9436
  } ], [ ":%S", function(d) {
9437
    return d.getSeconds();
9438
  } ], [ "%I:%M", function(d) {
9439
    return d.getMinutes();
9440
  } ], [ "%I %p", function(d) {
9441
    return d.getHours();
9442
  } ], [ "%a %d", function(d) {
9443
    return d.getDay() && d.getDate() != 1;
9444
  } ], [ "%b %d", function(d) {
9445
    return d.getDate() != 1;
9446
  } ], [ "%B", function(d) {
9447
    return d.getMonth();
9448
  } ], [ "%Y", d3_true ] ]);
9449
  var d3_time_scaleMilliseconds = {
9450
    range: function(start, stop, step) {
9451
      return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
9452
    },
9453
    floor: d3_identity,
9454
    ceil: d3_identity
9455
  };
9456
  d3_time_scaleLocalMethods.year = d3_time.year;
9457
  d3_time.scale = function() {
9458
    return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
9459
  };
9460
  var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
9461
    return [ m[0].utc, m[1] ];
9462
  });
9463
  var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
9464
    return d.getUTCMilliseconds();
9465
  } ], [ ":%S", function(d) {
9466
    return d.getUTCSeconds();
9467
  } ], [ "%I:%M", function(d) {
9468
    return d.getUTCMinutes();
9469
  } ], [ "%I %p", function(d) {
9470
    return d.getUTCHours();
9471
  } ], [ "%a %d", function(d) {
9472
    return d.getUTCDay() && d.getUTCDate() != 1;
9473
  } ], [ "%b %d", function(d) {
9474
    return d.getUTCDate() != 1;
9475
  } ], [ "%B", function(d) {
9476
    return d.getUTCMonth();
9477
  } ], [ "%Y", d3_true ] ]);
9478
  d3_time_scaleUtcMethods.year = d3_time.year.utc;
9479
  d3_time.scale.utc = function() {
9480
    return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
9481
  };
9482
  d3.text = d3_xhrType(function(request) {
9483
    return request.responseText;
9484
  });
9485
  d3.json = function(url, callback) {
9486
    return d3_xhr(url, "application/json", d3_json, callback);
9487
  };
9488
  function d3_json(request) {
9489
    return JSON.parse(request.responseText);
9490
  }
9491
  d3.html = function(url, callback) {
9492
    return d3_xhr(url, "text/html", d3_html, callback);
9493
  };
9494
  function d3_html(request) {
9495
    var range = d3_document.createRange();
9496
    range.selectNode(d3_document.body);
9497
    return range.createContextualFragment(request.responseText);
9498
  }
9499
  d3.xml = d3_xhrType(function(request) {
9500
    return request.responseXML;
9501
  });
9502
  if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3;
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9503
  this.d3 = d3;
9504
}();
9505
(function(exports){
9506
crossfilter.version = "1.3.11";
9507
function crossfilter_identity(d) {
9508
  return d;
9509
}
9510
crossfilter.permute = permute;
9511
9512
function permute(array, index) {
9513
  for (var i = 0, n = index.length, copy = new Array(n); i < n; ++i) {
9514
    copy[i] = array[index[i]];
9515
  }
9516
  return copy;
9517
}
9518
var bisect = crossfilter.bisect = bisect_by(crossfilter_identity);
9519
9520
bisect.by = bisect_by;
9521
9522
function bisect_by(f) {
9523
9524
  // Locate the insertion point for x in a to maintain sorted order. The
9525
  // arguments lo and hi may be used to specify a subset of the array which
9526
  // should be considered; by default the entire array is used. If x is already
9527
  // present in a, the insertion point will be before (to the left of) any
9528
  // existing entries. The return value is suitable for use as the first
9529
  // argument to `array.splice` assuming that a is already sorted.
9530
  //
9531
  // The returned insertion point i partitions the array a into two halves so
9532
  // that all v < x for v in a[lo:i] for the left side and all v >= x for v in
9533
  // a[i:hi] for the right side.
9534
  function bisectLeft(a, x, lo, hi) {
9535
    while (lo < hi) {
9536
      var mid = lo + hi >>> 1;
9537
      if (f(a[mid]) < x) lo = mid + 1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9538
      else hi = mid;
9539
    }
9540
    return lo;
9541
  }
9542
9543
  // Similar to bisectLeft, but returns an insertion point which comes after (to
9544
  // the right of) any existing entries of x in a.
9545
  //
9546
  // The returned insertion point i partitions the array into two halves so that
9547
  // all v <= x for v in a[lo:i] for the left side and all v > x for v in
9548
  // a[i:hi] for the right side.
9549
  function bisectRight(a, x, lo, hi) {
9550
    while (lo < hi) {
9551
      var mid = lo + hi >>> 1;
9552
      if (x < f(a[mid])) hi = mid;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9553
      else lo = mid + 1;
9554
    }
9555
    return lo;
9556
  }
9557
9558
  bisectRight.right = bisectRight;
9559
  bisectRight.left = bisectLeft;
9560
  return bisectRight;
9561
}
9562
var heap = crossfilter.heap = heap_by(crossfilter_identity);
9563
9564
heap.by = heap_by;
9565
9566
function heap_by(f) {
9567
9568
  // Builds a binary heap within the specified array a[lo:hi]. The heap has the
9569
  // property such that the parent a[lo+i] is always less than or equal to its
9570
  // two children: a[lo+2*i+1] and a[lo+2*i+2].
9571
  function heap(a, lo, hi) {
9572
    var n = hi - lo,
9573
        i = (n >>> 1) + 1;
9574
    while (--i > 0) sift(a, i, n, lo);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9575
    return a;
9576
  }
9577
9578
  // Sorts the specified array a[lo:hi] in descending order, assuming it is
9579
  // already a heap.
9580
  function sort(a, lo, hi) {
9581
    var n = hi - lo,
9582
        t;
9583
    while (--n > 0) t = a[lo], a[lo] = a[lo + n], a[lo + n] = t, sift(a, 1, n, lo);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9584
    return a;
9585
  }
9586
9587
  // Sifts the element a[lo+i-1] down the heap, where the heap is the contiguous
9588
  // slice of array a[lo:lo+n]. This method can also be used to update the heap
9589
  // incrementally, without incurring the full cost of reconstructing the heap.
9590
  function sift(a, i, n, lo) {
9591
    var d = a[--lo + i],
9592
        x = f(d),
9593
        child;
9594
    while ((child = i << 1) <= n) {
9595
      if (child < n && f(a[lo + child]) > f(a[lo + child + 1])) child++;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9596
      if (x <= f(a[lo + child])) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9597
      a[lo + i] = a[lo + child];
9598
      i = child;
9599
    }
9600
    a[lo + i] = d;
9601
  }
9602
9603
  heap.sort = sort;
9604
  return heap;
9605
}
9606
var heapselect = crossfilter.heapselect = heapselect_by(crossfilter_identity);
9607
9608
heapselect.by = heapselect_by;
9609
9610
function heapselect_by(f) {
9611
  var heap = heap_by(f);
9612
9613
  // Returns a new array containing the top k elements in the array a[lo:hi].
9614
  // The returned array is not sorted, but maintains the heap property. If k is
9615
  // greater than hi - lo, then fewer than k elements will be returned. The
9616
  // order of elements in a is unchanged by this operation.
9617
  function heapselect(a, lo, hi, k) {
9618
    var queue = new Array(k = Math.min(hi - lo, k)),
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
9619
        min,
9620
        i,
9621
        x,
9622
        d;
9623
9624
    for (i = 0; i < k; ++i) queue[i] = a[lo++];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9625
    heap(queue, 0, k);
9626
9627
    if (lo < hi) {
9628
      min = f(queue[0]);
9629
      do {
9630
        if (x = f(d = a[lo]) > min) {
0 ignored issues
show
Unused Code introduced by
The variable x seems to be never used. Consider removing it.
Loading history...
9631
          queue[0] = d;
9632
          min = f(heap(queue, 0, k)[0]);
9633
        }
9634
      } while (++lo < hi);
9635
    }
9636
9637
    return queue;
9638
  }
9639
9640
  return heapselect;
9641
}
9642
var insertionsort = crossfilter.insertionsort = insertionsort_by(crossfilter_identity);
9643
9644
insertionsort.by = insertionsort_by;
9645
9646
function insertionsort_by(f) {
9647
9648
  function insertionsort(a, lo, hi) {
9649
    for (var i = lo + 1; i < hi; ++i) {
9650
      for (var j = i, t = a[i], x = f(t); j > lo && f(a[j - 1]) > x; --j) {
9651
        a[j] = a[j - 1];
9652
      }
9653
      a[j] = t;
9654
    }
9655
    return a;
9656
  }
9657
9658
  return insertionsort;
9659
}
9660
// Algorithm designed by Vladimir Yaroslavskiy.
9661
// Implementation based on the Dart project; see lib/dart/LICENSE for details.
9662
9663
var quicksort = crossfilter.quicksort = quicksort_by(crossfilter_identity);
9664
9665
quicksort.by = quicksort_by;
9666
9667
function quicksort_by(f) {
9668
  var insertionsort = insertionsort_by(f);
9669
9670
  function sort(a, lo, hi) {
9671
    return (hi - lo < quicksort_sizeThreshold
9672
        ? insertionsort
9673
        : quicksort)(a, lo, hi);
9674
  }
9675
9676
  function quicksort(a, lo, hi) {
9677
    // Compute the two pivots by looking at 5 elements.
9678
    var sixth = (hi - lo) / 6 | 0,
9679
        i1 = lo + sixth,
9680
        i5 = hi - 1 - sixth,
9681
        i3 = lo + hi - 1 >> 1,  // The midpoint.
9682
        i2 = i3 - sixth,
9683
        i4 = i3 + sixth;
9684
9685
    var e1 = a[i1], x1 = f(e1),
9686
        e2 = a[i2], x2 = f(e2),
9687
        e3 = a[i3], x3 = f(e3),
9688
        e4 = a[i4], x4 = f(e4),
9689
        e5 = a[i5], x5 = f(e5);
9690
9691
    var t;
9692
9693
    // Sort the selected 5 elements using a sorting network.
9694
    if (x1 > x2) t = e1, e1 = e2, e2 = t, t = x1, x1 = x2, x2 = t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9695
    if (x4 > x5) t = e4, e4 = e5, e5 = t, t = x4, x4 = x5, x5 = t;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9696
    if (x1 > x3) t = e1, e1 = e3, e3 = t, t = x1, x1 = x3, x3 = t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9697
    if (x2 > x3) t = e2, e2 = e3, e3 = t, t = x2, x2 = x3, x3 = t;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9698
    if (x1 > x4) t = e1, e1 = e4, e4 = t, t = x1, x1 = x4, x4 = t;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Unused Code introduced by
The assignment to variable x1 seems to be never used. Consider removing it.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9699
    if (x3 > x4) t = e3, e3 = e4, e4 = t, t = x3, x3 = x4, x4 = t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9700
    if (x2 > x5) t = e2, e2 = e5, e5 = t, t = x2, x2 = x5, x5 = t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9701
    if (x2 > x3) t = e2, e2 = e3, e3 = t, t = x2, x2 = x3, x3 = t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Unused Code introduced by
The assignment to variable x3 seems to be never used. Consider removing it.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9702
    if (x4 > x5) t = e4, e4 = e5, e5 = t, t = x4, x4 = x5, x5 = t;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Unused Code introduced by
The assignment to variable x5 seems to be never used. Consider removing it.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
9703
9704
    var pivot1 = e2, pivotValue1 = x2,
9705
        pivot2 = e4, pivotValue2 = x4;
9706
9707
    // e2 and e4 have been saved in the pivot variables. They will be written
9708
    // back, once the partitioning is finished.
9709
    a[i1] = e1;
9710
    a[i2] = a[lo];
9711
    a[i3] = e3;
9712
    a[i4] = a[hi - 1];
9713
    a[i5] = e5;
9714
9715
    var less = lo + 1,   // First element in the middle partition.
9716
        great = hi - 2;  // Last element in the middle partition.
9717
9718
    // Note that for value comparison, <, <=, >= and > coerce to a primitive via
9719
    // Object.prototype.valueOf; == and === do not, so in order to be consistent
9720
    // with natural order (such as for Date objects), we must do two compares.
9721
    var pivotsEqual = pivotValue1 <= pivotValue2 && pivotValue1 >= pivotValue2;
9722
    if (pivotsEqual) {
9723
9724
      // Degenerated case where the partitioning becomes a dutch national flag
9725
      // problem.
9726
      //
9727
      // [ |  < pivot  | == pivot | unpartitioned | > pivot  | ]
9728
      //  ^             ^          ^             ^            ^
9729
      // left         less         k           great         right
9730
      //
9731
      // a[left] and a[right] are undefined and are filled after the
9732
      // partitioning.
9733
      //
9734
      // Invariants:
9735
      //   1) for x in ]left, less[ : x < pivot.
9736
      //   2) for x in [less, k[ : x == pivot.
9737
      //   3) for x in ]great, right[ : x > pivot.
9738 View Code Duplication
      for (var k = less; k <= great; ++k) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9739
        var ek = a[k], xk = f(ek);
9740
        if (xk < pivotValue1) {
9741
          if (k !== less) {
9742
            a[k] = a[less];
9743
            a[less] = ek;
9744
          }
9745
          ++less;
9746
        } else if (xk > pivotValue1) {
9747
9748
          // Find the first element <= pivot in the range [k - 1, great] and
9749
          // put [:ek:] there. We know that such an element must exist:
9750
          // When k == less, then el3 (which is equal to pivot) lies in the
9751
          // interval. Otherwise a[k - 1] == pivot and the search stops at k-1.
9752
          // Note that in the latter case invariant 2 will be violated for a
9753
          // short amount of time. The invariant will be restored when the
9754
          // pivots are put into their final positions.
9755
          while (true) {
9756
            var greatValue = f(a[great]);
9757
            if (greatValue > pivotValue1) {
9758
              great--;
9759
              // This is the only location in the while-loop where a new
9760
              // iteration is started.
9761
              continue;
0 ignored issues
show
Unused Code introduced by
This continue has no effect on the loop flow and can be removed.
Loading history...
9762
            } else if (greatValue < pivotValue1) {
9763
              // Triple exchange.
9764
              a[k] = a[less];
9765
              a[less++] = a[great];
9766
              a[great--] = ek;
9767
              break;
9768
            } else {
9769
              a[k] = a[great];
9770
              a[great--] = ek;
9771
              // Note: if great < k then we will exit the outer loop and fix
9772
              // invariant 2 (which we just violated).
9773
              break;
9774
            }
9775
          }
9776
        }
9777
      }
9778
    } else {
9779
9780
      // We partition the list into three parts:
9781
      //  1. < pivot1
9782
      //  2. >= pivot1 && <= pivot2
9783
      //  3. > pivot2
9784
      //
9785
      // During the loop we have:
9786
      // [ | < pivot1 | >= pivot1 && <= pivot2 | unpartitioned  | > pivot2  | ]
9787
      //  ^            ^                        ^              ^             ^
9788
      // left         less                     k              great        right
9789
      //
9790
      // a[left] and a[right] are undefined and are filled after the
9791
      // partitioning.
9792
      //
9793
      // Invariants:
9794
      //   1. for x in ]left, less[ : x < pivot1
9795
      //   2. for x in [less, k[ : pivot1 <= x && x <= pivot2
9796
      //   3. for x in ]great, right[ : x > pivot2
9797 View Code Duplication
      for (var k = less; k <= great; k++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable k already seems to be declared on line 9738. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9798
        var ek = a[k], xk = f(ek);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable ek already seems to be declared on line 9739. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Comprehensibility Naming Best Practice introduced by
The variable xk already seems to be declared on line 9739. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
9799
        if (xk < pivotValue1) {
9800
          if (k !== less) {
9801
            a[k] = a[less];
9802
            a[less] = ek;
9803
          }
9804
          ++less;
9805
        } else {
9806
          if (xk > pivotValue2) {
9807
            while (true) {
9808
              var greatValue = f(a[great]);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable greatValue already seems to be declared on line 9756. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
9809
              if (greatValue > pivotValue2) {
9810
                great--;
9811
                if (great < k) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9812
                // This is the only location inside the loop where a new
9813
                // iteration is started.
9814
                continue;
0 ignored issues
show
Unused Code introduced by
This continue has no effect on the loop flow and can be removed.
Loading history...
9815
              } else {
9816
                // a[great] <= pivot2.
9817
                if (greatValue < pivotValue1) {
9818
                  // Triple exchange.
9819
                  a[k] = a[less];
9820
                  a[less++] = a[great];
9821
                  a[great--] = ek;
9822
                } else {
9823
                  // a[great] >= pivot1.
9824
                  a[k] = a[great];
9825
                  a[great--] = ek;
9826
                }
9827
                break;
9828
              }
9829
            }
9830
          }
9831
        }
9832
      }
9833
    }
9834
9835
    // Move pivots into their final positions.
9836
    // We shrunk the list from both sides (a[left] and a[right] have
9837
    // meaningless values in them) and now we move elements from the first
9838
    // and third partition into these locations so that we can store the
9839
    // pivots.
9840
    a[lo] = a[less - 1];
9841
    a[less - 1] = pivot1;
9842
    a[hi - 1] = a[great + 1];
9843
    a[great + 1] = pivot2;
9844
9845
    // The list is now partitioned into three partitions:
9846
    // [ < pivot1   | >= pivot1 && <= pivot2   |  > pivot2   ]
9847
    //  ^            ^                        ^             ^
9848
    // left         less                     great        right
9849
9850
    // Recursive descent. (Don't include the pivot values.)
9851
    sort(a, lo, less - 1);
9852
    sort(a, great + 2, hi);
9853
9854
    if (pivotsEqual) {
9855
      // All elements in the second partition are equal to the pivot. No
9856
      // need to sort them.
9857
      return a;
9858
    }
9859
9860
    // In theory it should be enough to call _doSort recursively on the second
9861
    // partition.
9862
    // The Android source however removes the pivot elements from the recursive
9863
    // call if the second partition is too large (more than 2/3 of the list).
9864
    if (less < i1 && great > i5) {
9865
      var lessValue, greatValue;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable greatValue already seems to be declared on line 9756. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
9866
      while ((lessValue = f(a[less])) <= pivotValue1 && lessValue >= pivotValue1) ++less;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9867
      while ((greatValue = f(a[great])) <= pivotValue2 && greatValue >= pivotValue2) --great;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9868
9869
      // Copy paste of the previous 3-way partitioning with adaptions.
9870
      //
9871
      // We partition the list into three parts:
9872
      //  1. == pivot1
9873
      //  2. > pivot1 && < pivot2
9874
      //  3. == pivot2
9875
      //
9876
      // During the loop we have:
9877
      // [ == pivot1 | > pivot1 && < pivot2 | unpartitioned  | == pivot2 ]
9878
      //              ^                      ^              ^
9879
      //            less                     k              great
9880
      //
9881
      // Invariants:
9882
      //   1. for x in [ *, less[ : x == pivot1
9883
      //   2. for x in [less, k[ : pivot1 < x && x < pivot2
9884
      //   3. for x in ]great, * ] : x == pivot2
9885 View Code Duplication
      for (var k = less; k <= great; k++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable k already seems to be declared on line 9738. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9886
        var ek = a[k], xk = f(ek);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable xk already seems to be declared on line 9739. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Comprehensibility Naming Best Practice introduced by
The variable ek already seems to be declared on line 9739. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
9887
        if (xk <= pivotValue1 && xk >= pivotValue1) {
9888
          if (k !== less) {
9889
            a[k] = a[less];
9890
            a[less] = ek;
9891
          }
9892
          less++;
9893
        } else {
9894
          if (xk <= pivotValue2 && xk >= pivotValue2) {
9895
            while (true) {
9896
              var greatValue = f(a[great]);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable greatValue already seems to be declared on line 9756. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
9897
              if (greatValue <= pivotValue2 && greatValue >= pivotValue2) {
9898
                great--;
9899
                if (great < k) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9900
                // This is the only location inside the loop where a new
9901
                // iteration is started.
9902
                continue;
0 ignored issues
show
Unused Code introduced by
This continue has no effect on the loop flow and can be removed.
Loading history...
9903
              } else {
9904
                // a[great] < pivot2.
9905
                if (greatValue < pivotValue1) {
9906
                  // Triple exchange.
9907
                  a[k] = a[less];
9908
                  a[less++] = a[great];
9909
                  a[great--] = ek;
9910
                } else {
9911
                  // a[great] == pivot1.
9912
                  a[k] = a[great];
9913
                  a[great--] = ek;
9914
                }
9915
                break;
9916
              }
9917
            }
9918
          }
9919
        }
9920
      }
9921
    }
9922
9923
    // The second partition has now been cleared of pivot elements and looks
9924
    // as follows:
9925
    // [  *  |  > pivot1 && < pivot2  | * ]
9926
    //        ^                      ^
9927
    //       less                  great
9928
    // Sort the second partition using recursive descent.
9929
9930
    // The second partition looks as follows:
9931
    // [  *  |  >= pivot1 && <= pivot2  | * ]
9932
    //        ^                        ^
9933
    //       less                    great
9934
    // Simply sort it by recursive descent.
9935
9936
    return sort(a, less, great + 1);
9937
  }
9938
9939
  return sort;
9940
}
9941
9942
var quicksort_sizeThreshold = 32;
9943
var crossfilter_array8 = crossfilter_arrayUntyped,
9944
    crossfilter_array16 = crossfilter_arrayUntyped,
9945
    crossfilter_array32 = crossfilter_arrayUntyped,
9946
    crossfilter_arrayLengthen = crossfilter_arrayLengthenUntyped,
9947
    crossfilter_arrayWiden = crossfilter_arrayWidenUntyped;
9948
9949
if (typeof Uint8Array !== "undefined") {
9950
  crossfilter_array8 = function(n) { return new Uint8Array(n); };
9951
  crossfilter_array16 = function(n) { return new Uint16Array(n); };
9952
  crossfilter_array32 = function(n) { return new Uint32Array(n); };
9953
9954
  crossfilter_arrayLengthen = function(array, length) {
9955
    if (array.length >= length) return array;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9956
    var copy = new array.constructor(length);
9957
    copy.set(array);
9958
    return copy;
9959
  };
9960
9961
  crossfilter_arrayWiden = function(array, width) {
9962
    var copy;
9963
    switch (width) {
9964
      case 16: copy = crossfilter_array16(array.length); break;
9965
      case 32: copy = crossfilter_array32(array.length); break;
9966
      default: throw new Error("invalid array width!");
9967
    }
9968
    copy.set(array);
9969
    return copy;
9970
  };
9971
}
9972
9973
function crossfilter_arrayUntyped(n) {
9974
  var array = new Array(n), i = -1;
9975
  while (++i < n) array[i] = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9976
  return array;
9977
}
9978
9979
function crossfilter_arrayLengthenUntyped(array, length) {
9980
  var n = array.length;
9981
  while (n < length) array[n++] = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9982
  return array;
9983
}
9984
9985
function crossfilter_arrayWidenUntyped(array, width) {
9986
  if (width > 32) throw new Error("invalid array width!");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9987
  return array;
9988
}
9989
function crossfilter_filterExact(bisect, value) {
9990
  return function(values) {
9991
    var n = values.length;
9992
    return [bisect.left(values, value, 0, n), bisect.right(values, value, 0, n)];
9993
  };
9994
}
9995
9996
function crossfilter_filterRange(bisect, range) {
9997
  var min = range[0],
9998
      max = range[1];
9999
  return function(values) {
10000
    var n = values.length;
10001
    return [bisect.left(values, min, 0, n), bisect.left(values, max, 0, n)];
10002
  };
10003
}
10004
10005
function crossfilter_filterAll(values) {
10006
  return [0, values.length];
10007
}
10008
function crossfilter_null() {
10009
  return null;
10010
}
10011
function crossfilter_zero() {
10012
  return 0;
10013
}
10014
function crossfilter_reduceIncrement(p) {
10015
  return p + 1;
10016
}
10017
10018
function crossfilter_reduceDecrement(p) {
10019
  return p - 1;
10020
}
10021
10022
function crossfilter_reduceAdd(f) {
10023
  return function(p, v) {
10024
    return p + +f(v);
10025
  };
10026
}
10027
10028
function crossfilter_reduceSubtract(f) {
10029
  return function(p, v) {
10030
    return p - f(v);
10031
  };
10032
}
10033
exports.crossfilter = crossfilter;
10034
10035
function crossfilter() {
10036
  var crossfilter = {
10037
    add: add,
10038
    remove: removeData,
10039
    dimension: dimension,
10040
    groupAll: groupAll,
10041
    size: size
10042
  };
10043
10044
  var data = [], // the records
10045
      n = 0, // the number of records; data.length
10046
      m = 0, // a bit mask representing which dimensions are in use
10047
      M = 8, // number of dimensions that can fit in `filters`
10048
      filters = crossfilter_array8(0), // M bits per record; 1 is filtered out
10049
      filterListeners = [], // when the filters change
10050
      dataListeners = [], // when data is added
10051
      removeDataListeners = []; // when data is removed
10052
10053
  // Adds the specified new records to this crossfilter.
10054
  function add(newData) {
10055
    var n0 = n,
10056
        n1 = newData.length;
10057
10058
    // If there's actually new data to add…
10059
    // Merge the new data into the existing data.
10060
    // Lengthen the filter bitset to handle the new records.
10061
    // Notify listeners (dimensions and groups) that new data is available.
10062
    if (n1) {
10063
      data = data.concat(newData);
10064
      filters = crossfilter_arrayLengthen(filters, n += n1);
10065
      dataListeners.forEach(function(l) { l(newData, n0, n1); });
10066
    }
10067
10068
    return crossfilter;
10069
  }
10070
10071
  // Removes all records that match the current filters.
10072
  function removeData() {
10073
    var newIndex = crossfilter_index(n, n),
10074
        removed = [];
10075
    for (var i = 0, j = 0; i < n; ++i) {
10076
      if (filters[i]) newIndex[i] = j++;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10077
      else removed.push(i);
10078
    }
10079
10080
    // Remove all matching records from groups.
10081
    filterListeners.forEach(function(l) { l(0, [], removed); });
10082
10083
    // Update indexes.
10084
    removeDataListeners.forEach(function(l) { l(newIndex); });
10085
10086
    // Remove old filters and data by overwriting.
10087
    for (var i = 0, j = 0, k; i < n; ++i) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable j already seems to be declared on line 10075. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 10075. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
10088
      if (k = filters[i]) {
10089
        if (i !== j) filters[j] = k, data[j] = data[i];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10090
        ++j;
10091
      }
10092
    }
10093
    data.length = j;
10094
    while (n > j) filters[--n] = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable n is changed as part of the while loop for example by --n on line 10094. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
10095
  }
10096
10097
  // Adds a new dimension with the specified value accessor function.
10098
  function dimension(value) {
10099
    var dimension = {
10100
      filter: filter,
10101
      filterExact: filterExact,
10102
      filterRange: filterRange,
10103
      filterFunction: filterFunction,
10104
      filterAll: filterAll,
10105
      top: top,
10106
      bottom: bottom,
10107
      group: group,
10108
      groupAll: groupAll,
10109
      dispose: dispose,
10110
      remove: dispose // for backwards-compatibility
10111
    };
10112
10113
    var one = ~m & -~m, // lowest unset bit as mask, e.g., 00001000
10114
        zero = ~one, // inverted one, e.g., 11110111
10115
        values, // sorted, cached array
10116
        index, // value rank ↦ object id
10117
        newValues, // temporary array storing newly-added values
10118
        newIndex, // temporary array storing newly-added index
10119
        sort = quicksort_by(function(i) { return newValues[i]; }),
10120
        refilter = crossfilter_filterAll, // for recomputing filter
10121
        refilterFunction, // the custom filter function in use
10122
        indexListeners = [], // when data is added
10123
        dimensionGroups = [],
10124
        lo0 = 0,
10125
        hi0 = 0;
10126
10127
    // Updating a dimension is a two-stage process. First, we must update the
10128
    // associated filters for the newly-added records. Once all dimensions have
10129
    // updated their filters, the groups are notified to update.
10130
    dataListeners.unshift(preAdd);
10131
    dataListeners.push(postAdd);
10132
10133
    removeDataListeners.push(removeData);
10134
10135
    // Incorporate any existing data into this dimension, and make sure that the
10136
    // filter bitset is wide enough to handle the new dimension.
10137
    m |= one;
10138
    if (M >= 32 ? !one : m & (1 << M) - 1) {
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
10139
      filters = crossfilter_arrayWiden(filters, M <<= 1);
10140
    }
10141
    preAdd(data, 0, n);
10142
    postAdd(data, 0, n);
10143
10144
    // Incorporates the specified new records into this dimension.
10145
    // This function is responsible for updating filters, values, and index.
10146
    function preAdd(newData, n0, n1) {
10147
10148
      // Permute new values into natural order using a sorted index.
10149
      newValues = newData.map(value);
10150
      newIndex = sort(crossfilter_range(n1), 0, n1);
10151
      newValues = permute(newValues, newIndex);
10152
10153
      // Bisect newValues to determine which new records are selected.
10154
      var bounds = refilter(newValues), lo1 = bounds[0], hi1 = bounds[1], i;
10155
      if (refilterFunction) {
10156
        for (i = 0; i < n1; ++i) {
10157
          if (!refilterFunction(newValues[i], i)) filters[newIndex[i] + n0] |= one;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10158
        }
10159
      } else {
10160
        for (i = 0; i < lo1; ++i) filters[newIndex[i] + n0] |= one;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10161
        for (i = hi1; i < n1; ++i) filters[newIndex[i] + n0] |= one;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10162
      }
10163
10164
      // If this dimension previously had no data, then we don't need to do the
10165
      // more expensive merge operation; use the new values and index as-is.
10166
      if (!n0) {
10167
        values = newValues;
10168
        index = newIndex;
10169
        lo0 = lo1;
10170
        hi0 = hi1;
10171
        return;
10172
      }
10173
10174
      var oldValues = values,
10175
          oldIndex = index,
10176
          i0 = 0,
10177
          i1 = 0;
10178
10179
      // Otherwise, create new arrays into which to merge new and old.
10180
      values = new Array(n);
10181
      index = crossfilter_index(n, n);
10182
10183
      // Merge the old and new sorted values, and old and new index.
10184
      for (i = 0; i0 < n0 && i1 < n1; ++i) {
10185
        if (oldValues[i0] < newValues[i1]) {
10186
          values[i] = oldValues[i0];
10187
          index[i] = oldIndex[i0++];
10188
        } else {
10189
          values[i] = newValues[i1];
10190
          index[i] = newIndex[i1++] + n0;
10191
        }
10192
      }
10193
10194
      // Add any remaining old values.
10195
      for (; i0 < n0; ++i0, ++i) {
10196
        values[i] = oldValues[i0];
10197
        index[i] = oldIndex[i0];
10198
      }
10199
10200
      // Add any remaining new values.
10201
      for (; i1 < n1; ++i1, ++i) {
10202
        values[i] = newValues[i1];
10203
        index[i] = newIndex[i1] + n0;
10204
      }
10205
10206
      // Bisect again to recompute lo0 and hi0.
10207
      bounds = refilter(values), lo0 = bounds[0], hi0 = bounds[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10208
    }
10209
10210
    // When all filters have updated, notify index listeners of the new values.
10211
    function postAdd(newData, n0, n1) {
10212
      indexListeners.forEach(function(l) { l(newValues, newIndex, n0, n1); });
10213
      newValues = newIndex = null;
10214
    }
10215
10216
    function removeData(reIndex) {
10217
      for (var i = 0, j = 0, k; i < n; ++i) {
10218
        if (filters[k = index[i]]) {
10219
          if (i !== j) values[j] = values[i];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10220
          index[j] = reIndex[k];
10221
          ++j;
10222
        }
10223
      }
10224
      values.length = j;
10225
      while (j < n) index[j++] = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10226
10227
      // Bisect again to recompute lo0 and hi0.
10228
      var bounds = refilter(values);
10229
      lo0 = bounds[0], hi0 = bounds[1];
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10230
    }
10231
10232
    // Updates the selected values based on the specified bounds [lo, hi].
10233
    // This implementation is used by all the public filter methods.
10234
    function filterIndexBounds(bounds) {
10235
      var lo1 = bounds[0],
10236
          hi1 = bounds[1];
10237
10238
      if (refilterFunction) {
10239
        refilterFunction = null;
10240
        filterIndexFunction(function(d, i) { return lo1 <= i && i < hi1; });
10241
        lo0 = lo1;
10242
        hi0 = hi1;
10243
        return dimension;
10244
      }
10245
10246
      var i,
10247
          j,
10248
          k,
10249
          added = [],
10250
          removed = [];
10251
10252
      // Fast incremental update based on previous lo index.
10253
      if (lo1 < lo0) {
10254
        for (i = lo1, j = Math.min(lo0, hi1); i < j; ++i) {
10255
          filters[k = index[i]] ^= one;
10256
          added.push(k);
10257
        }
10258
      } else if (lo1 > lo0) {
10259
        for (i = lo0, j = Math.min(lo1, hi0); i < j; ++i) {
10260
          filters[k = index[i]] ^= one;
10261
          removed.push(k);
10262
        }
10263
      }
10264
10265
      // Fast incremental update based on previous hi index.
10266
      if (hi1 > hi0) {
10267
        for (i = Math.max(lo1, hi0), j = hi1; i < j; ++i) {
10268
          filters[k = index[i]] ^= one;
10269
          added.push(k);
10270
        }
10271
      } else if (hi1 < hi0) {
10272
        for (i = Math.max(lo0, hi1), j = hi0; i < j; ++i) {
10273
          filters[k = index[i]] ^= one;
10274
          removed.push(k);
10275
        }
10276
      }
10277
10278
      lo0 = lo1;
10279
      hi0 = hi1;
10280
      filterListeners.forEach(function(l) { l(one, added, removed); });
10281
      return dimension;
10282
    }
10283
10284
    // Filters this dimension using the specified range, value, or null.
10285
    // If the range is null, this is equivalent to filterAll.
10286
    // If the range is an array, this is equivalent to filterRange.
10287
    // Otherwise, this is equivalent to filterExact.
10288
    function filter(range) {
10289
      return range == null
10290
          ? filterAll() : Array.isArray(range)
10291
          ? filterRange(range) : typeof range === "function"
10292
          ? filterFunction(range)
10293
          : filterExact(range);
10294
    }
10295
10296
    // Filters this dimension to select the exact value.
10297
    function filterExact(value) {
10298
      return filterIndexBounds((refilter = crossfilter_filterExact(bisect, value))(values));
10299
    }
10300
10301
    // Filters this dimension to select the specified range [lo, hi].
10302
    // The lower bound is inclusive, and the upper bound is exclusive.
10303
    function filterRange(range) {
10304
      return filterIndexBounds((refilter = crossfilter_filterRange(bisect, range))(values));
10305
    }
10306
10307
    // Clears any filters on this dimension.
10308
    function filterAll() {
10309
      return filterIndexBounds((refilter = crossfilter_filterAll)(values));
10310
    }
10311
10312
    // Filters this dimension using an arbitrary function.
10313
    function filterFunction(f) {
10314
      refilter = crossfilter_filterAll;
10315
10316
      filterIndexFunction(refilterFunction = f);
10317
10318
      lo0 = 0;
10319
      hi0 = n;
10320
10321
      return dimension;
10322
    }
10323
10324
    function filterIndexFunction(f) {
10325
      var i,
10326
          k,
10327
          x,
10328
          added = [],
10329
          removed = [];
10330
10331
      for (i = 0; i < n; ++i) {
10332
        if (!(filters[k = index[i]] & one) ^ !!(x = f(values[i], i))) {
10333
          if (x) filters[k] &= zero, added.push(k);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10334
          else filters[k] |= one, removed.push(k);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10335
        }
10336
      }
10337
      filterListeners.forEach(function(l) { l(one, added, removed); });
10338
    }
10339
10340
    // Returns the top K selected records based on this dimension's order.
10341
    // Note: observes this dimension's filter, unlike group and groupAll.
10342
    function top(k) {
10343
      var array = [],
10344
          i = hi0,
10345
          j;
10346
10347
      while (--i >= lo0 && k > 0) {
10348
        if (!filters[j = index[i]]) {
10349
          array.push(data[j]);
10350
          --k;
10351
        }
10352
      }
10353
10354
      return array;
10355
    }
10356
10357
    // Returns the bottom K selected records based on this dimension's order.
10358
    // Note: observes this dimension's filter, unlike group and groupAll.
10359
    function bottom(k) {
10360
      var array = [],
10361
          i = lo0,
10362
          j;
10363
10364
      while (i < hi0 && k > 0) {
10365
        if (!filters[j = index[i]]) {
10366
          array.push(data[j]);
10367
          --k;
10368
        }
10369
        i++;
10370
      }
10371
10372
      return array;
10373
    }
10374
10375
    // Adds a new group to this dimension, using the specified key function.
10376
    function group(key) {
10377
      var group = {
10378
        top: top,
10379
        all: all,
10380
        reduce: reduce,
10381
        reduceCount: reduceCount,
10382
        reduceSum: reduceSum,
10383
        order: order,
10384
        orderNatural: orderNatural,
10385
        size: size,
10386
        dispose: dispose,
10387
        remove: dispose // for backwards-compatibility
10388
      };
10389
10390
      // Ensure that this group will be removed when the dimension is removed.
10391
      dimensionGroups.push(group);
10392
10393
      var groups, // array of {key, value}
10394
          groupIndex, // object id ↦ group id
10395
          groupWidth = 8,
10396
          groupCapacity = crossfilter_capacity(groupWidth),
10397
          k = 0, // cardinality
10398
          select,
10399
          heap,
10400
          reduceAdd,
10401
          reduceRemove,
10402
          reduceInitial,
10403
          update = crossfilter_null,
10404
          reset = crossfilter_null,
10405
          resetNeeded = true,
10406
          groupAll = key === crossfilter_null;
10407
10408
      if (arguments.length < 1) key = crossfilter_identity;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10409
10410
      // The group listens to the crossfilter for when any dimension changes, so
10411
      // that it can update the associated reduce values. It must also listen to
10412
      // the parent dimension for when data is added, and compute new keys.
10413
      filterListeners.push(update);
10414
      indexListeners.push(add);
10415
      removeDataListeners.push(removeData);
10416
10417
      // Incorporate any existing data into the grouping.
10418
      add(values, index, 0, n);
10419
10420
      // Incorporates the specified new values into this group.
10421
      // This function is responsible for updating groups and groupIndex.
10422
      function add(newValues, newIndex, n0, n1) {
10423
        var oldGroups = groups,
10424
            reIndex = crossfilter_index(k, groupCapacity),
10425
            add = reduceAdd,
10426
            initial = reduceInitial,
10427
            k0 = k, // old cardinality
10428
            i0 = 0, // index of old group
10429
            i1 = 0, // index of new record
10430
            j, // object id
10431
            g0, // old group
10432
            x0, // old key
10433
            x1, // new key
10434
            g, // group to add
10435
            x; // key of group to add
10436
10437
        // If a reset is needed, we don't need to update the reduce values.
10438
        if (resetNeeded) add = initial = crossfilter_null;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10439
10440
        // Reset the new groups (k is a lower bound).
10441
        // Also, make sure that groupIndex exists and is long enough.
10442
        groups = new Array(k), k = 0;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10443
        groupIndex = k0 > 1 ? crossfilter_arrayLengthen(groupIndex, n) : crossfilter_index(n, groupCapacity);
10444
10445
        // Get the first old key (x0 of g0), if it exists.
10446
        if (k0) x0 = (g0 = oldGroups[0]).key;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10447
10448
        // Find the first new key (x1), skipping NaN keys.
10449
        while (i1 < n1 && !((x1 = key(newValues[i1])) >= x1)) ++i1;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10450
10451
        // While new keys remain…
10452
        while (i1 < n1) {
10453
10454
          // Determine the lesser of the two current keys; new and old.
10455
          // If there are no old keys remaining, then always add the new key.
10456
          if (g0 && x0 <= x1) {
0 ignored issues
show
Bug introduced by
The variable x0 does not seem to be initialized in case k0 on line 10446 is false. Are you sure this can never be the case?
Loading history...
Bug introduced by
The variable x1 seems to not be initialized for all possible execution paths.
Loading history...
10457
            g = g0, x = x0;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10458
10459
            // Record the new index of the old group.
10460
            reIndex[i0] = k;
10461
10462
            // Retrieve the next old key.
10463
            if (g0 = oldGroups[++i0]) x0 = g0.key;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10464
          } else {
10465
            g = {key: x1, value: initial()}, x = x1;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10466
          }
10467
10468
          // Add the lesser group.
10469
          groups[k] = g;
10470
10471
          // Add any selected records belonging to the added group, while
10472
          // advancing the new key and populating the associated group index.
10473
          while (!(x1 > x)) {
10474
            groupIndex[j = newIndex[i1] + n0] = k;
10475
            if (!(filters[j] & zero)) g.value = add(g.value, data[j]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10476
            if (++i1 >= n1) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10477
            x1 = key(newValues[i1]);
10478
          }
10479
10480
          groupIncrement();
10481
        }
10482
10483
        // Add any remaining old groups that were greater than all new keys.
10484
        // No incremental reduce is needed; these groups have no new records.
10485
        // Also record the new index of the old group.
10486
        while (i0 < k0) {
10487
          groups[reIndex[i0] = k] = oldGroups[i0++];
10488
          groupIncrement();
10489
        }
10490
10491
        // If we added any new groups before any old groups,
10492
        // update the group index of all the old records.
10493
        if (k > i0) for (i0 = 0; i0 < n0; ++i0) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10494
          groupIndex[i0] = reIndex[groupIndex[i0]];
10495
        }
10496
10497
        // Modify the update and reset behavior based on the cardinality.
10498
        // If the cardinality is less than or equal to one, then the groupIndex
10499
        // is not needed. If the cardinality is zero, then there are no records
10500
        // and therefore no groups to update or reset. Note that we also must
10501
        // change the registered listener to point to the new method.
10502
        j = filterListeners.indexOf(update);
10503
        if (k > 1) {
10504
          update = updateMany;
10505
          reset = resetMany;
10506
        } else {
10507
          if (!k && groupAll) {
10508
            k = 1;
10509
            groups = [{key: null, value: initial()}];
10510
          }
10511
          if (k === 1) {
10512
            update = updateOne;
10513
            reset = resetOne;
10514
          } else {
10515
            update = crossfilter_null;
10516
            reset = crossfilter_null;
10517
          }
10518
          groupIndex = null;
10519
        }
10520
        filterListeners[j] = update;
10521
10522
        // Count the number of added groups,
10523
        // and widen the group index as needed.
10524
        function groupIncrement() {
10525
          if (++k === groupCapacity) {
10526
            reIndex = crossfilter_arrayWiden(reIndex, groupWidth <<= 1);
10527
            groupIndex = crossfilter_arrayWiden(groupIndex, groupWidth);
10528
            groupCapacity = crossfilter_capacity(groupWidth);
10529
          }
10530
        }
10531
      }
10532
10533
      function removeData() {
10534
        if (k > 1) {
10535
          var oldK = k,
10536
              oldGroups = groups,
10537
              seenGroups = crossfilter_index(oldK, oldK);
10538
10539
          // Filter out non-matches by copying matching group index entries to
10540
          // the beginning of the array.
10541
          for (var i = 0, j = 0; i < n; ++i) {
10542
            if (filters[i]) {
10543
              seenGroups[groupIndex[j] = groupIndex[i]] = 1;
10544
              ++j;
10545
            }
10546
          }
10547
10548
          // Reassemble groups including only those groups that were referred
10549
          // to by matching group index entries.  Note the new group index in
10550
          // seenGroups.
10551
          groups = [], k = 0;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10552
          for (i = 0; i < oldK; ++i) {
10553
            if (seenGroups[i]) {
10554
              seenGroups[i] = k++;
0 ignored issues
show
Bug introduced by
The variable k is changed as part of the for loop for example by k++ on line 10554. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
10555
              groups.push(oldGroups[i]);
10556
            }
10557
          }
10558
10559
          if (k > 1) {
10560
            // Reindex the group index using seenGroups to find the new index.
10561
            for (var i = 0; i < j; ++i) groupIndex[i] = seenGroups[groupIndex[i]];
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 10541. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10562
          } else {
10563
            groupIndex = null;
10564
          }
10565
          filterListeners[filterListeners.indexOf(update)] = k > 1
10566
              ? (reset = resetMany, update = updateMany)
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10567
              : k === 1 ? (reset = resetOne, update = updateOne)
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10568
              : reset = update = crossfilter_null;
10569
        } else if (k === 1) {
10570
          if (groupAll) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10571
          for (var i = 0; i < n; ++i) if (filters[i]) return;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 10541. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10572
          groups = [], k = 0;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10573
          filterListeners[filterListeners.indexOf(update)] =
10574
          update = reset = crossfilter_null;
10575
        }
10576
      }
10577
10578
      // Reduces the specified selected or deselected records.
10579
      // This function is only used when the cardinality is greater than 1.
10580 View Code Duplication
      function updateMany(filterOne, added, removed) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
10581
        if (filterOne === one || resetNeeded) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10582
10583
        var i,
10584
            k,
10585
            n,
10586
            g;
10587
10588
        // Add the added values.
10589
        for (i = 0, n = added.length; i < n; ++i) {
10590
          if (!(filters[k = added[i]] & zero)) {
10591
            g = groups[groupIndex[k]];
10592
            g.value = reduceAdd(g.value, data[k]);
10593
          }
10594
        }
10595
10596
        // Remove the removed values.
10597
        for (i = 0, n = removed.length; i < n; ++i) {
10598
          if ((filters[k = removed[i]] & zero) === filterOne) {
10599
            g = groups[groupIndex[k]];
10600
            g.value = reduceRemove(g.value, data[k]);
10601
          }
10602
        }
10603
      }
10604
10605
      // Reduces the specified selected or deselected records.
10606
      // This function is only used when the cardinality is 1.
10607 View Code Duplication
      function updateOne(filterOne, added, removed) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
10608
        if (filterOne === one || resetNeeded) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10609
10610
        var i,
10611
            k,
10612
            n,
10613
            g = groups[0];
10614
10615
        // Add the added values.
10616
        for (i = 0, n = added.length; i < n; ++i) {
10617
          if (!(filters[k = added[i]] & zero)) {
10618
            g.value = reduceAdd(g.value, data[k]);
10619
          }
10620
        }
10621
10622
        // Remove the removed values.
10623
        for (i = 0, n = removed.length; i < n; ++i) {
10624
          if ((filters[k = removed[i]] & zero) === filterOne) {
10625
            g.value = reduceRemove(g.value, data[k]);
10626
          }
10627
        }
10628
      }
10629
10630
      // Recomputes the group reduce values from scratch.
10631
      // This function is only used when the cardinality is greater than 1.
10632
      function resetMany() {
10633
        var i,
10634
            g;
10635
10636
        // Reset all group values.
10637
        for (i = 0; i < k; ++i) {
10638
          groups[i].value = reduceInitial();
10639
        }
10640
10641
        // Add any selected records.
10642
        for (i = 0; i < n; ++i) {
10643
          if (!(filters[i] & zero)) {
10644
            g = groups[groupIndex[i]];
10645
            g.value = reduceAdd(g.value, data[i]);
10646
          }
10647
        }
10648
      }
10649
10650
      // Recomputes the group reduce values from scratch.
10651
      // This function is only used when the cardinality is 1.
10652
      function resetOne() {
10653
        var i,
10654
            g = groups[0];
10655
10656
        // Reset the singleton group values.
10657
        g.value = reduceInitial();
10658
10659
        // Add any selected records.
10660
        for (i = 0; i < n; ++i) {
10661
          if (!(filters[i] & zero)) {
10662
            g.value = reduceAdd(g.value, data[i]);
10663
          }
10664
        }
10665
      }
10666
10667
      // Returns the array of group values, in the dimension's natural order.
10668
      function all() {
10669
        if (resetNeeded) reset(), resetNeeded = false;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10670
        return groups;
10671
      }
10672
10673
      // Returns a new array containing the top K group values, in reduce order.
10674
      function top(k) {
10675
        var top = select(all(), 0, groups.length, k);
10676
        return heap.sort(top, 0, top.length);
10677
      }
10678
10679
      // Sets the reduce behavior for this group to use the specified functions.
10680
      // This method lazily recomputes the reduce values, waiting until needed.
10681
      function reduce(add, remove, initial) {
10682
        reduceAdd = add;
10683
        reduceRemove = remove;
10684
        reduceInitial = initial;
10685
        resetNeeded = true;
10686
        return group;
10687
      }
10688
10689
      // A convenience method for reducing by count.
10690
      function reduceCount() {
10691
        return reduce(crossfilter_reduceIncrement, crossfilter_reduceDecrement, crossfilter_zero);
10692
      }
10693
10694
      // A convenience method for reducing by sum(value).
10695
      function reduceSum(value) {
10696
        return reduce(crossfilter_reduceAdd(value), crossfilter_reduceSubtract(value), crossfilter_zero);
10697
      }
10698
10699
      // Sets the reduce order, using the specified accessor.
10700
      function order(value) {
10701
        select = heapselect_by(valueOf);
10702
        heap = heap_by(valueOf);
10703
        function valueOf(d) { return value(d.value); }
10704
        return group;
10705
      }
10706
10707
      // A convenience method for natural ordering by reduce value.
10708
      function orderNatural() {
10709
        return order(crossfilter_identity);
10710
      }
10711
10712
      // Returns the cardinality of this group, irrespective of any filters.
10713
      function size() {
10714
        return k;
10715
      }
10716
10717
      // Removes this group and associated event listeners.
10718
      function dispose() {
10719
        var i = filterListeners.indexOf(update);
10720
        if (i >= 0) filterListeners.splice(i, 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10721
        i = indexListeners.indexOf(add);
10722
        if (i >= 0) indexListeners.splice(i, 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10723
        i = removeDataListeners.indexOf(removeData);
10724
        if (i >= 0) removeDataListeners.splice(i, 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10725
        return group;
10726
      }
10727
10728
      return reduceCount().orderNatural();
10729
    }
10730
10731
    // A convenience function for generating a singleton group.
10732
    function groupAll() {
10733
      var g = group(crossfilter_null), all = g.all;
10734
      delete g.all;
10735
      delete g.top;
10736
      delete g.order;
10737
      delete g.orderNatural;
10738
      delete g.size;
10739
      g.value = function() { return all()[0].value; };
10740
      return g;
10741
    }
10742
10743
    // Removes this dimension and associated groups and event listeners.
10744
    function dispose() {
10745
      dimensionGroups.forEach(function(group) { group.dispose(); });
10746
      var i = dataListeners.indexOf(preAdd);
10747
      if (i >= 0) dataListeners.splice(i, 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10748
      i = dataListeners.indexOf(postAdd);
10749
      if (i >= 0) dataListeners.splice(i, 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10750
      i = removeDataListeners.indexOf(removeData);
10751
      if (i >= 0) removeDataListeners.splice(i, 1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10752
      m &= zero;
10753
      return filterAll();
10754
    }
10755
10756
    return dimension;
10757
  }
10758
10759
  // A convenience method for groupAll on a dummy dimension.
10760
  // This implementation can be optimized since it always has cardinality 1.
10761
  function groupAll() {
10762
    var group = {
10763
      reduce: reduce,
10764
      reduceCount: reduceCount,
10765
      reduceSum: reduceSum,
10766
      value: value,
10767
      dispose: dispose,
10768
      remove: dispose // for backwards-compatibility
10769
    };
10770
10771
    var reduceValue,
10772
        reduceAdd,
10773
        reduceRemove,
10774
        reduceInitial,
10775
        resetNeeded = true;
10776
10777
    // The group listens to the crossfilter for when any dimension changes, so
10778
    // that it can update the reduce value. It must also listen to the parent
10779
    // dimension for when data is added.
10780
    filterListeners.push(update);
10781
    dataListeners.push(add);
10782
10783
    // For consistency; actually a no-op since resetNeeded is true.
10784
    add(data, 0, n);
0 ignored issues
show
Bug introduced by
The call to add seems to have too many arguments starting with n.
Loading history...
10785
10786
    // Incorporates the specified new values into this group.
10787
    function add(newData, n0) {
10788
      var i;
10789
10790
      if (resetNeeded) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10791
10792
      // Add the added values.
10793
      for (i = n0; i < n; ++i) {
10794
        if (!filters[i]) {
10795
          reduceValue = reduceAdd(reduceValue, data[i]);
0 ignored issues
show
Bug introduced by
The variable reduceValue seems to not be initialized for all possible execution paths. Are you sure reduceAdd handles undefined variables?
Loading history...
10796
        }
10797
      }
10798
    }
10799
10800
    // Reduces the specified selected or deselected records.
10801
    function update(filterOne, added, removed) {
10802
      var i,
10803
          k,
10804
          n;
10805
10806
      if (resetNeeded) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10807
10808
      // Add the added values.
10809
      for (i = 0, n = added.length; i < n; ++i) {
10810
        if (!filters[k = added[i]]) {
10811
          reduceValue = reduceAdd(reduceValue, data[k]);
0 ignored issues
show
Bug introduced by
The variable reduceValue seems to not be initialized for all possible execution paths. Are you sure reduceAdd handles undefined variables?
Loading history...
10812
        }
10813
      }
10814
10815
      // Remove the removed values.
10816
      for (i = 0, n = removed.length; i < n; ++i) {
10817
        if (filters[k = removed[i]] === filterOne) {
10818
          reduceValue = reduceRemove(reduceValue, data[k]);
10819
        }
10820
      }
10821
    }
10822
10823
    // Recomputes the group reduce value from scratch.
10824
    function reset() {
10825
      var i;
10826
10827
      reduceValue = reduceInitial();
10828
10829
      for (i = 0; i < n; ++i) {
10830
        if (!filters[i]) {
10831
          reduceValue = reduceAdd(reduceValue, data[i]);
0 ignored issues
show
Bug introduced by
The variable reduceValue is changed as part of the for loop for example by reduceAdd(reduceValue, data.i) on line 10831. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
10832
        }
10833
      }
10834
    }
10835
10836
    // Sets the reduce behavior for this group to use the specified functions.
10837
    // This method lazily recomputes the reduce value, waiting until needed.
10838
    function reduce(add, remove, initial) {
10839
      reduceAdd = add;
10840
      reduceRemove = remove;
10841
      reduceInitial = initial;
10842
      resetNeeded = true;
10843
      return group;
10844
    }
10845
10846
    // A convenience method for reducing by count.
10847
    function reduceCount() {
10848
      return reduce(crossfilter_reduceIncrement, crossfilter_reduceDecrement, crossfilter_zero);
10849
    }
10850
10851
    // A convenience method for reducing by sum(value).
10852
    function reduceSum(value) {
10853
      return reduce(crossfilter_reduceAdd(value), crossfilter_reduceSubtract(value), crossfilter_zero);
10854
    }
10855
10856
    // Returns the computed reduce value.
10857
    function value() {
10858
      if (resetNeeded) reset(), resetNeeded = false;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10859
      return reduceValue;
10860
    }
10861
10862
    // Removes this group and associated event listeners.
10863
    function dispose() {
10864
      var i = filterListeners.indexOf(update);
10865
      if (i >= 0) filterListeners.splice(i);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10866
      i = dataListeners.indexOf(add);
10867
      if (i >= 0) dataListeners.splice(i);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10868
      return group;
10869
    }
10870
10871
    return reduceCount();
10872
  }
10873
10874
  // Returns the number of records in this crossfilter, irrespective of any filters.
10875
  function size() {
10876
    return n;
10877
  }
10878
10879
  return arguments.length
10880
      ? add(arguments[0])
10881
      : crossfilter;
10882
}
10883
10884
// Returns an array of size n, big enough to store ids up to m.
10885
function crossfilter_index(n, m) {
10886
  return (m < 0x101
10887
      ? crossfilter_array8 : m < 0x10001
10888
      ? crossfilter_array16
10889
      : crossfilter_array32)(n);
10890
}
10891
10892
// Constructs a new array of size n, with sequential values from 0 to n - 1.
10893
function crossfilter_range(n) {
10894
  var range = crossfilter_index(n, n);
10895
  for (var i = -1; ++i < n;) range[i] = i;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
10896
  return range;
10897
}
10898
10899
function crossfilter_capacity(w) {
10900
  return w === 8
10901
      ? 0x100 : w === 16
10902
      ? 0x10000
10903
      : 0x100000000;
10904
}
10905
})(typeof exports !== 'undefined' && exports || this);
10906
10907
/*!
10908
 *  dc 2.0.0-beta.11
10909
 *  http://dc-js.github.io/dc.js/
10910
 *  Copyright 2012-2015 Nick Zhu & the dc.js Developers
10911
 *  https://github.com/dc-js/dc.js/blob/master/AUTHORS
10912
 *
10913
 *  Licensed under the Apache License, Version 2.0 (the "License");
10914
 *  you may not use this file except in compliance with the License.
10915
 *  You may obtain a copy of the License at
10916
 *
10917
 *      http://www.apache.org/licenses/LICENSE-2.0
10918
 *
10919
 *  Unless required by applicable law or agreed to in writing, software
10920
 *  distributed under the License is distributed on an "AS IS" BASIS,
10921
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10922
 *  See the License for the specific language governing permissions and
10923
 *  limitations under the License.
10924
 */
10925
(function() { function _dc(d3, crossfilter) {
10926
'use strict';
10927
10928
/**
10929
#### Version 2.0.0-beta.11
10930
The entire dc.js library is scoped under the **dc** name space. It does not introduce anything else
10931
into the global name space.
10932
#### Function Chaining
10933
Most dc functions are designed to allow function chaining, meaning they return the current chart
10934
instance whenever it is appropriate. This way chart configuration can be written in the following
10935
style:
10936
```js
10937
chart.width(300)
10938
    .height(300)
10939
    .filter('sunday')
10940
```
10941
The getter forms of functions do not participate in function chaining because they necessarily
10942
return values that are not the chart.  (Although some, such as `.svg` and `.xAxis`, return values
10943
that are chainable d3 objects.)
10944
10945
**/
10946
10947
/*jshint -W062*/
10948
/*jshint -W079*/
10949
var dc = {
10950
    version: '2.0.0-beta.11',
10951
    constants: {
10952
        CHART_CLASS: 'dc-chart',
10953
        DEBUG_GROUP_CLASS: 'debug',
10954
        STACK_CLASS: 'stack',
10955
        DESELECTED_CLASS: 'deselected',
10956
        SELECTED_CLASS: 'selected',
10957
        NODE_INDEX_NAME: '__index__',
10958
        GROUP_INDEX_NAME: '__group_index__',
10959
        DEFAULT_CHART_GROUP: '__default_chart_group__',
10960
        EVENT_DELAY: 40,
10961
        NEGLIGIBLE_NUMBER: 1e-10
10962
    },
10963
    _renderlet: null
10964
};
10965
10966
dc.chartRegistry = function () {
10967
    // chartGroup:string => charts:array
10968
    var _chartMap = {};
10969
10970
    function initializeChartGroup(group) {
10971
        if (!group) {
10972
            group = dc.constants.DEFAULT_CHART_GROUP;
10973
        }
10974
10975
        if (!_chartMap[group]) {
10976
            _chartMap[group] = [];
10977
        }
10978
10979
        return group;
10980
    }
10981
10982
    return {
10983
        has: function (chart) {
10984
            for (var e in _chartMap) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
10985
                if (_chartMap[e].indexOf(chart) >= 0) {
10986
                    return true;
10987
                }
10988
            }
10989
            return false;
10990
        },
10991
10992
        register: function (chart, group) {
10993
            group = initializeChartGroup(group);
10994
            _chartMap[group].push(chart);
10995
        },
10996
10997
        deregister: function (chart, group) {
10998
            group = initializeChartGroup(group);
10999
            for (var i = 0; i < _chartMap[group].length; i++) {
11000
                if (_chartMap[group][i].anchorName() === chart.anchorName()) {
11001
                    _chartMap[group].splice(i, 1);
11002
                    break;
11003
                }
11004
            }
11005
        },
11006
11007
        clear: function (group) {
11008
            if (group) {
11009
                delete _chartMap[group];
11010
            } else {
11011
                _chartMap = {};
11012
            }
11013
        },
11014
11015
        list: function (group) {
11016
            group = initializeChartGroup(group);
11017
            return _chartMap[group];
11018
        }
11019
    };
11020
}();
11021
/*jshint +W062 */
11022
/*jshint +W079*/
11023
11024
dc.registerChart = function (chart, group) {
11025
    dc.chartRegistry.register(chart, group);
11026
};
11027
11028
dc.deregisterChart = function (chart, group) {
11029
    dc.chartRegistry.deregister(chart, group);
11030
};
11031
11032
dc.hasChart = function (chart) {
11033
    return dc.chartRegistry.has(chart);
11034
};
11035
11036
dc.deregisterAllCharts = function (group) {
11037
    dc.chartRegistry.clear(group);
11038
};
11039
11040
/**
11041
## Utilities
11042
**/
11043
11044
/**
11045
#### dc.filterAll([chartGroup])
11046
Clear all filters on all charts within the given chart group. If the chart group is not given then
11047
only charts that belong to the default chart group will be reset.
11048
**/
11049
dc.filterAll = function (group) {
11050
    var charts = dc.chartRegistry.list(group);
11051
    for (var i = 0; i < charts.length; ++i) {
11052
        charts[i].filterAll();
11053
    }
11054
};
11055
11056
/**
11057
#### dc.refocusAll([chartGroup])
11058
Reset zoom level / focus on all charts that belong to the given chart group. If the chart group is
11059
not given then only charts that belong to the default chart group will be reset.
11060
**/
11061
dc.refocusAll = function (group) {
11062
    var charts = dc.chartRegistry.list(group);
11063
    for (var i = 0; i < charts.length; ++i) {
11064
        if (charts[i].focus) {
11065
            charts[i].focus();
11066
        }
11067
    }
11068
};
11069
11070
/**
11071
#### dc.renderAll([chartGroup])
11072
Re-render all charts belong to the given chart group. If the chart group is not given then only
11073
charts that belong to the default chart group will be re-rendered.
11074
**/
11075
dc.renderAll = function (group) {
11076
    var charts = dc.chartRegistry.list(group);
11077
    for (var i = 0; i < charts.length; ++i) {
11078
        charts[i].render();
11079
    }
11080
11081
    if (dc._renderlet !== null) {
11082
        dc._renderlet(group);
11083
    }
11084
};
11085
11086
/**
11087
#### dc.redrawAll([chartGroup])
11088
Redraw all charts belong to the given chart group. If the chart group is not given then only charts
11089
that belong to the default chart group will be re-drawn. Redraw is different from re-render since
11090
when redrawing dc tries to update the graphic incrementally, using transitions, instead of starting
11091
from scratch.
11092
**/
11093
dc.redrawAll = function (group) {
11094
    var charts = dc.chartRegistry.list(group);
11095
    for (var i = 0; i < charts.length; ++i) {
11096
        charts[i].redraw();
11097
    }
11098
11099
    if (dc._renderlet !== null) {
11100
        dc._renderlet(group);
11101
    }
11102
};
11103
11104
/**
11105
#### dc.disableTransitions
11106
If this boolean is set truthy, all transitions will be disabled, and changes to the charts will happen
11107
immediately.  Default: false
11108
**/
11109
dc.disableTransitions = false;
11110
11111
dc.transition = function (selections, duration, callback) {
11112
    if (duration <= 0 || duration === undefined || dc.disableTransitions) {
11113
        return selections;
11114
    }
11115
11116
    var s = selections
11117
        .transition()
11118
        .duration(duration);
11119
11120
    if (typeof(callback) === 'function') {
11121
        callback(s);
11122
    }
11123
11124
    return s;
11125
};
11126
11127
dc.units = {};
11128
11129
/**
11130
#### dc.units.integers
11131
`dc.units.integers` is the default value for `xUnits` for the [Coordinate Grid
11132
Chart](#coordinate-grid-chart) and should be used when the x values are a sequence of integers.
11133
11134
It is a function that counts the number of integers in the range supplied in its start and end parameters.
11135
11136
```js
11137
chart.xUnits(dc.units.integers) // already the default
11138
```
11139
11140
**/
11141
dc.units.integers = function (s, e) {
11142
    return Math.abs(e - s);
11143
};
11144
11145
/**
11146
#### dc.units.ordinal
11147
This argument can be passed to the `xUnits` function of the to specify ordinal units for the x
11148
axis. Usually this parameter is used in combination with passing `d3.scale.ordinal()` to `.x`.
11149
11150
It just returns the domain passed to it, which for ordinal charts is an array of all values.
11151
11152
```js
11153
chart.xUnits(dc.units.ordinal)
11154
    .x(d3.scale.ordinal())
11155
```
11156
11157
**/
11158
dc.units.ordinal = function (s, e, domain) {
11159
    return domain;
11160
};
11161
11162
/**
11163
#### dc.units.fp.precision(precision)
11164
This function generates an argument for the [Coordinate Grid Chart's](#coordinate-grid-chart)
11165
`xUnits` function specifying that the x values are floating-point numbers with the given
11166
precision.
11167
11168
The returned function determines how many values at the given precision will fit into the range
11169
supplied in its start and end parameters.
11170
11171
```js
11172
// specify values (and ticks) every 0.1 units
11173
chart.xUnits(dc.units.fp.precision(0.1)
11174
// there are 500 units between 0.5 and 1 if the precision is 0.001
11175
var thousandths = dc.units.fp.precision(0.001);
11176
thousandths(0.5, 1.0) // returns 500
11177
```
11178
**/
11179
dc.units.fp = {};
11180
dc.units.fp.precision = function (precision) {
11181
    var _f = function (s, e) {
11182
        var d = Math.abs((e - s) / _f.resolution);
11183
        if (dc.utils.isNegligible(d - Math.floor(d))) {
11184
            return Math.floor(d);
11185
        } else {
11186
            return Math.ceil(d);
11187
        }
11188
    };
11189
    _f.resolution = precision;
11190
    return _f;
11191
};
11192
11193
dc.round = {};
11194
dc.round.floor = function (n) {
11195
    return Math.floor(n);
11196
};
11197
dc.round.ceil = function (n) {
11198
    return Math.ceil(n);
11199
};
11200
dc.round.round = function (n) {
11201
    return Math.round(n);
11202
};
11203
11204
dc.override = function (obj, functionName, newFunction) {
11205
    var existingFunction = obj[functionName];
11206
    obj['_' + functionName] = existingFunction;
11207
    obj[functionName] = newFunction;
11208
};
11209
11210
dc.renderlet = function (_) {
11211
    if (!arguments.length) {
11212
        return dc._renderlet;
11213
    }
11214
    dc._renderlet = _;
11215
    return dc;
11216
};
11217
11218
dc.instanceOfChart = function (o) {
11219
    return o instanceof Object && o.__dcFlag__ && true;
11220
};
11221
11222
dc.errors = {};
11223
11224
dc.errors.Exception = function (msg) {
11225
    var _msg = msg || 'Unexpected internal error';
11226
11227
    this.message = _msg;
11228
11229
    this.toString = function () {
11230
        return _msg;
11231
    };
11232
};
11233
11234
dc.errors.InvalidStateException = function () {
11235
    dc.errors.Exception.apply(this, arguments);
11236
};
11237
11238
dc.dateFormat = d3.time.format('%m/%d/%Y');
11239
11240
dc.printers = {};
11241
11242
dc.printers.filters = function (filters) {
11243
    var s = '';
11244
11245
    for (var i = 0; i < filters.length; ++i) {
11246
        if (i > 0) {
11247
            s += ', ';
11248
        }
11249
        s += dc.printers.filter(filters[i]);
11250
    }
11251
11252
    return s;
11253
};
11254
11255
dc.printers.filter = function (filter) {
11256
    var s = '';
11257
11258
    if (typeof filter !== 'undefined' && filter !== null) {
11259
        if (filter instanceof Array) {
11260
            if (filter.length >= 2) {
11261
                s = '[' + dc.utils.printSingleValue(filter[0]) + ' -> ' + dc.utils.printSingleValue(filter[1]) + ']';
11262
            } else if (filter.length >= 1) {
11263
                s = dc.utils.printSingleValue(filter[0]);
11264
            }
11265
        } else {
11266
            s = dc.utils.printSingleValue(filter);
11267
        }
11268
    }
11269
11270
    return s;
11271
};
11272
11273
dc.pluck = function (n, f) {
11274
    if (!f) {
11275
        return function (d) { return d[n]; };
11276
    }
11277
    return function (d, i) { return f.call(d, d[n], i); };
11278
};
11279
11280
dc.utils = {};
11281
11282
dc.utils.printSingleValue = function (filter) {
11283
    var s = '' + filter;
11284
11285
    if (filter instanceof Date) {
11286
        s = dc.dateFormat(filter);
11287
    } else if (typeof(filter) === 'string') {
11288
        s = filter;
11289
    } else if (dc.utils.isFloat(filter)) {
11290
        s = dc.utils.printSingleValue.fformat(filter);
11291
    } else if (dc.utils.isInteger(filter)) {
11292
        s = Math.round(filter);
11293
    }
11294
11295
    return s;
11296
};
11297
dc.utils.printSingleValue.fformat = d3.format('.2f');
11298
11299
// FIXME: these assume than any string r is a percentage (whether or not it
11300
// includes %). They also generate strange results if l is a string.
11301 View Code Duplication
dc.utils.add = function (l, r) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11302
    if (typeof r === 'string') {
11303
        r = r.replace('%', '');
11304
    }
11305
11306
    if (l instanceof Date) {
11307
        if (typeof r === 'string') {
11308
            r = +r;
11309
        }
11310
        var d = new Date();
11311
        d.setTime(l.getTime());
11312
        d.setDate(l.getDate() + r);
11313
        return d;
11314
    } else if (typeof r === 'string') {
11315
        var percentage = (+r / 100);
11316
        return l > 0 ? l * (1 + percentage) : l * (1 - percentage);
11317
    } else {
11318
        return l + r;
11319
    }
11320
};
11321
11322 View Code Duplication
dc.utils.subtract = function (l, r) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11323
    if (typeof r === 'string') {
11324
        r = r.replace('%', '');
11325
    }
11326
11327
    if (l instanceof Date) {
11328
        if (typeof r === 'string') {
11329
            r = +r;
11330
        }
11331
        var d = new Date();
11332
        d.setTime(l.getTime());
11333
        d.setDate(l.getDate() - r);
11334
        return d;
11335
    } else if (typeof r === 'string') {
11336
        var percentage = (+r / 100);
11337
        return l < 0 ? l * (1 + percentage) : l * (1 - percentage);
11338
    } else {
11339
        return l - r;
11340
    }
11341
};
11342
11343
dc.utils.isNumber = function (n) {
11344
    return n === +n;
11345
};
11346
11347
dc.utils.isFloat = function (n) {
11348
    return n === +n && n !== (n | 0);
11349
};
11350
11351
dc.utils.isInteger = function (n) {
11352
    return n === +n && n === (n | 0);
11353
};
11354
11355
dc.utils.isNegligible = function (n) {
11356
    return !dc.utils.isNumber(n) || (n < dc.constants.NEGLIGIBLE_NUMBER && n > -dc.constants.NEGLIGIBLE_NUMBER);
11357
};
11358
11359
dc.utils.clamp = function (val, min, max) {
11360
    return val < min ? min : (val > max ? max : val);
11361
};
11362
11363
var _idCounter = 0;
11364
dc.utils.uniqueId = function () {
11365
    return ++_idCounter;
11366
};
11367
11368
dc.utils.nameToId = function (name) {
11369
    return name.toLowerCase().replace(/[\s]/g, '_').replace(/[\.']/g, '');
11370
};
11371
11372
dc.utils.appendOrSelect = function (parent, selector, tag) {
11373
    tag = tag || selector;
11374
    var element = parent.select(selector);
11375
    if (element.empty()) {
11376
        element = parent.append(tag);
11377
    }
11378
    return element;
11379
};
11380
11381
dc.utils.safeNumber = function (n) { return dc.utils.isNumber(+n) ? +n : 0;};
11382
11383
dc.logger = {};
11384
11385
dc.logger.enableDebugLog = false;
11386
11387
dc.logger.warn = function (msg) {
11388
    if (console) {
11389
        if (console.warn) {
11390
            console.warn(msg);
11391
        } else if (console.log) {
11392
            console.log(msg);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
11393
        }
11394
    }
11395
11396
    return dc.logger;
11397
};
11398
11399
dc.logger.debug = function (msg) {
11400
    if (dc.logger.enableDebugLog && console) {
11401
        if (console.debug) {
11402
            console.debug(msg);
11403
        } else if (console.log) {
11404
            console.log(msg);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
11405
        }
11406
    }
11407
11408
    return dc.logger;
11409
};
11410
11411
dc.logger.deprecate = function (fn, msg) {
11412
    // Allow logging of deprecation
11413
    var warned = false;
11414
    function deprecated() {
11415
        if (!warned) {
11416
            dc.logger.warn(msg);
11417
            warned = true;
11418
        }
11419
        return fn.apply(this, arguments);
11420
    }
11421
    return deprecated;
11422
};
11423
11424
dc.events = {
11425
    current: null
11426
};
11427
11428
/**
11429
#### dc.events.trigger(function[, delay])
11430
This function triggers a throttled event function with a specified delay (in milli-seconds).  Events
11431
that are triggered repetitively due to user interaction such brush dragging might flood the library
11432
and invoke more renders than can be executed in time. Using this function to wrap your event
11433
function allows the library to smooth out the rendering by throttling events and only responding to
11434
the most recent event.
11435
11436
```js
11437
    chart.on('renderlet', function(chart) {
11438
        // smooth the rendering through event throttling
11439
        dc.events.trigger(function(){
11440
            // focus some other chart to the range selected by user on this chart
11441
            someOtherChart.focus(chart.filter());
11442
        });
11443
    })
11444
```
11445
**/
11446
dc.events.trigger = function (closure, delay) {
11447
    if (!delay) {
11448
        closure();
11449
        return;
11450
    }
11451
11452
    dc.events.current = closure;
11453
11454
    setTimeout(function () {
11455
        if (closure === dc.events.current) {
11456
            closure();
11457
        }
11458
    }, delay);
11459
};
11460
11461
dc.filters = {};
11462
11463
/**
11464
## Filters
11465
The dc.js filters are functions which are passed into crossfilter to chose which records will be
11466
accumulated to produce values for the charts.  In the crossfilter model, any filters applied on one
11467
dimension will affect all the other dimensions but not that one.  dc always applies a filter
11468
function to the dimension; the function combines multiple filters and if any of them accept a
11469
record, it is filtered in.
11470
11471
These filter constructors are used as appropriate by the various charts to implement brushing.  We
11472
mention below which chart uses which filter.  In some cases, many instances of a filter will be added.
11473
11474
**/
11475
11476
/**
11477
#### dc.filters.RangedFilter(low, high)
11478
 RangedFilter is a filter which accepts keys between `low` and `high`.  It is used to implement X
11479
 axis brushing for the [coordinate grid charts](#coordinate-grid-mixin).
11480
**/
11481
dc.filters.RangedFilter = function (low, high) {
11482
    var range = new Array(low, high);
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
11483
    range.isFiltered = function (value) {
11484
        return value >= this[0] && value < this[1];
11485
    };
11486
11487
    return range;
11488
};
11489
11490
/**
11491
#### dc.filters.TwoDimensionalFilter(array)
11492
 TwoDimensionalFilter is a filter which accepts a single two-dimensional value.  It is used by the
11493
 [heat map chart](#heat-map) to include particular cells as they are clicked.  (Rows and columns are
11494
 filtered by filtering all the cells in the row or column.)
11495
**/
11496
dc.filters.TwoDimensionalFilter = function (array) {
11497
    if (array === null) { return null; }
11498
11499
    var filter = array;
11500
    filter.isFiltered = function (value) {
11501
        return value.length && value.length === filter.length &&
11502
               value[0] === filter[0] && value[1] === filter[1];
11503
    };
11504
11505
    return filter;
11506
};
11507
11508
/**
11509
#### dc.filters.RangedTwoDimensionalFilter(array)
11510
 The RangedTwoDimensionalFilter allows filtering all values which fit within a rectangular
11511
 region. It is used by the [scatter plot](#scatter-plot) to implement rectangular brushing.
11512
11513
 It takes two two-dimensional points in the form `[[x1,y1],[x2,y2]]`, and normalizes them so that
11514
 `x1 <= x2` and `y1 <- y2`. It then returns a filter which accepts any points which are in the
11515
 rectangular range including the lower values but excluding the higher values.
11516
11517
 If an array of two values are given to the RangedTwoDimensionalFilter, it interprets the values as
11518
 two x coordinates `x1` and `x2` and returns a filter which accepts any points for which `x1 <= x <
11519
 x2`.
11520
 **/
11521
dc.filters.RangedTwoDimensionalFilter = function (array) {
11522
    if (array === null) { return null; }
11523
11524
    var filter = array;
11525
    var fromBottomLeft;
11526
11527
    if (filter[0] instanceof Array) {
11528
        fromBottomLeft = [
11529
            [Math.min(array[0][0], array[1][0]), Math.min(array[0][1], array[1][1])],
11530
            [Math.max(array[0][0], array[1][0]), Math.max(array[0][1], array[1][1])]
11531
        ];
11532
    } else {
11533
        fromBottomLeft = [[array[0], -Infinity], [array[1], Infinity]];
11534
    }
11535
11536
    filter.isFiltered = function (value) {
11537
        var x, y;
11538
11539
        if (value instanceof Array) {
11540
            if (value.length !== 2) {
11541
                return false;
11542
            }
11543
            x = value[0];
11544
            y = value[1];
11545
        } else {
11546
            x = value;
11547
            y = fromBottomLeft[0][1];
11548
        }
11549
11550
        return x >= fromBottomLeft[0][0] && x < fromBottomLeft[1][0] &&
11551
               y >= fromBottomLeft[0][1] && y < fromBottomLeft[1][1];
11552
    };
11553
11554
    return filter;
11555
};
11556
11557
/**
11558
## Base Mixin
11559
Base Mixin is an abstract functional object representing a basic dc chart object
11560
for all chart and widget implementations. Methods from the Base Mixin are inherited
11561
and available on all chart implementation in the DC library.
11562
**/
11563
dc.baseMixin = function (_chart) {
11564
    _chart.__dcFlag__ = dc.utils.uniqueId();
11565
11566
    var _dimension;
11567
    var _group;
11568
11569
    var _anchor;
11570
    var _root;
11571
    var _svg;
11572
    var _isChild;
11573
11574
    var _minWidth = 200;
11575
    var _defaultWidth = function (element) {
11576
        var width = element && element.getBoundingClientRect && element.getBoundingClientRect().width;
11577
        return (width && width > _minWidth) ? width : _minWidth;
11578
    };
11579
    var _width = _defaultWidth;
11580
11581
    var _minHeight = 200;
11582
    var _defaultHeight = function (element) {
11583
        var height = element && element.getBoundingClientRect && element.getBoundingClientRect().height;
11584
        return (height && height > _minHeight) ? height : _minHeight;
11585
    };
11586
    var _height = _defaultHeight;
11587
11588
    var _keyAccessor = dc.pluck('key');
11589
    var _valueAccessor = dc.pluck('value');
11590
    var _label = dc.pluck('key');
11591
11592
    var _ordering = dc.pluck('key');
11593
    var _orderSort;
11594
11595
    var _renderLabel = false;
11596
11597
    var _title = function (d) {
11598
        return _chart.keyAccessor()(d) + ': ' + _chart.valueAccessor()(d);
11599
    };
11600
    var _renderTitle = true;
11601
11602
    var _transitionDuration = 750;
11603
11604
    var _filterPrinter = dc.printers.filters;
11605
11606
    var _mandatoryAttributes = ['dimension', 'group'];
11607
11608
    var _chartGroup = dc.constants.DEFAULT_CHART_GROUP;
11609
11610
    var _listeners = d3.dispatch(
11611
        'preRender',
11612
        'postRender',
11613
        'preRedraw',
11614
        'postRedraw',
11615
        'filtered',
11616
        'zoomed',
11617
        'renderlet',
11618
        'pretransition');
11619
11620
    var _legend;
11621
11622
    var _filters = [];
11623
    var _filterHandler = function (dimension, filters) {
11624
        dimension.filter(null);
11625
11626
        if (filters.length === 0) {
11627
            dimension.filter(null);
11628
        } else {
11629
            dimension.filterFunction(function (d) {
11630
                for (var i = 0; i < filters.length; i++) {
11631
                    var filter = filters[i];
11632
                    if (filter.isFiltered && filter.isFiltered(d)) {
11633
                        return true;
11634
                    } else if (filter <= d && filter >= d) {
11635
                        return true;
11636
                    }
11637
                }
11638
                return false;
11639
            });
11640
        }
11641
        return filters;
11642
    };
11643
11644
    var _data = function (group) {
11645
        return group.all();
11646
    };
11647
11648
    /**
11649
    #### .width([value])
11650
    Set or get the width attribute of a chart. See `.height` below for further description of the
11651
    behavior.
11652
11653
    **/
11654
    _chart.width = function (w) {
11655
        if (!arguments.length) {
11656
            return _width(_root.node());
11657
        }
11658
        _width = d3.functor(w || _defaultWidth);
11659
        return _chart;
11660
    };
11661
11662
    /**
11663
    #### .height([value])
11664
    Set or get the height attribute of a chart. The height is applied to the SVG element generated by
11665
    the chart when rendered (or rerendered). If a value is given, then it will be used to calculate
11666
    the new height and the chart returned for method chaining.  The value can either be a numeric, a
11667
    function, or falsy. If no value is specified then the value of the current height attribute will
11668
    be returned.
11669
11670
    By default, without an explicit height being given, the chart will select the width of its
11671
    anchor element. If that isn't possible it defaults to 200. Setting the value falsy will return
11672
    the chart to the default behavior
11673
11674
    Examples:
11675
11676
    ```js
11677
    chart.height(250); // Set the chart's height to 250px;
11678
    chart.height(function(anchor) { return doSomethingWith(anchor); }); // set the chart's height with a function
11679
    chart.height(null); // reset the height to the default auto calculation
11680
    ```
11681
11682
    **/
11683
    _chart.height = function (h) {
11684
        if (!arguments.length) {
11685
            return _height(_root.node());
11686
        }
11687
        _height = d3.functor(h || _defaultHeight);
11688
        return _chart;
11689
    };
11690
11691
    /**
11692
    #### .minWidth([value])
11693
    Set or get the minimum width attribute of a chart. This only applicable if the width is
11694
    calculated by dc.
11695
11696
    **/
11697
    _chart.minWidth = function (w) {
11698
        if (!arguments.length) {
11699
            return _minWidth;
11700
        }
11701
        _minWidth = w;
11702
        return _chart;
11703
    };
11704
11705
    /**
11706
    #### .minHeight([value])
11707
    Set or get the minimum height attribute of a chart. This only applicable if the height is
11708
    calculated by dc.
11709
11710
    **/
11711
    _chart.minHeight = function (w) {
11712
        if (!arguments.length) {
11713
            return _minHeight;
11714
        }
11715
        _minHeight = w;
11716
        return _chart;
11717
    };
11718
11719
    /**
11720
    #### .dimension([value]) - **mandatory**
11721
    Set or get the dimension attribute of a chart. In dc a dimension can be any valid [crossfilter
11722
    dimension](https://github.com/square/crossfilter/wiki/API-Reference#wiki-dimension).
11723
11724
    If a value is given, then it will be used as the new dimension. If no value is specified then
11725
    the current dimension will be returned.
11726
11727
    **/
11728
    _chart.dimension = function (d) {
11729
        if (!arguments.length) {
11730
            return _dimension;
11731
        }
11732
        _dimension = d;
11733
        _chart.expireCache();
11734
        return _chart;
11735
    };
11736
11737
    /**
11738
    #### .data([callback])
11739
    Set the data callback or retrieve the chart's data set. The data callback is passed the chart's
11740
    group and by default will return `group.all()`. This behavior may be modified to, for instance,
11741
    return only the top 5 groups:
11742
    ```
11743
        chart.data(function(group) {
11744
            return group.top(5);
11745
        });
11746
    ```
11747
    **/
11748
    _chart.data = function (d) {
11749
        if (!arguments.length) {
11750
            return _data.call(_chart, _group);
11751
        }
11752
        _data = d3.functor(d);
11753
        _chart.expireCache();
11754
        return _chart;
11755
    };
11756
11757
    /**
11758
    #### .group([value, [name]]) - **mandatory**
11759
    Set or get the group attribute of a chart. In dc a group is a [crossfilter
11760
    group](https://github.com/square/crossfilter/wiki/API-Reference#wiki-group). Usually the group
11761
    should be created from the particular dimension associated with the same chart. If a value is
11762
    given, then it will be used as the new group.
11763
11764
    If no value specified then the current group will be returned.
11765
    If `name` is specified then it will be used to generate legend label.
11766
11767
    **/
11768
    _chart.group = function (g, name) {
11769
        if (!arguments.length) {
11770
            return _group;
11771
        }
11772
        _group = g;
11773
        _chart._groupName = name;
11774
        _chart.expireCache();
11775
        return _chart;
11776
    };
11777
11778
    /**
11779
    #### .ordering([orderFunction])
11780
    Get or set an accessor to order ordinal charts
11781
    **/
11782
    _chart.ordering = function (o) {
11783
        if (!arguments.length) {
11784
            return _ordering;
11785
        }
11786
        _ordering = o;
11787
        _orderSort = crossfilter.quicksort.by(_ordering);
11788
        _chart.expireCache();
11789
        return _chart;
11790
    };
11791
11792
    _chart._computeOrderedGroups = function (data) {
11793
        var dataCopy = data.slice(0);
11794
11795
        if (dataCopy.length <= 1) {
11796
            return dataCopy;
11797
        }
11798
11799
        if (!_orderSort) {
11800
            _orderSort = crossfilter.quicksort.by(_ordering);
11801
        }
11802
11803
        return _orderSort(dataCopy, 0, dataCopy.length);
11804
    };
11805
11806
    /**
11807
    #### .filterAll()
11808
    Clear all filters associated with this chart.
11809
11810
    **/
11811
    _chart.filterAll = function () {
11812
        return _chart.filter(null);
11813
    };
11814
11815
    /**
11816
    #### .select(selector)
11817
    Execute d3 single selection in the chart's scope using the given selector and return the d3
11818
    selection. Roughly the same as:
11819
    ```js
11820
    d3.select('#chart-id').select(selector);
11821
    ```
11822
    This function is **not chainable** since it does not return a chart instance; however the d3
11823
    selection result can be chained to d3 function calls.
11824
11825
    **/
11826
    _chart.select = function (s) {
11827
        return _root.select(s);
11828
    };
11829
11830
    /**
11831
    #### .selectAll(selector)
11832
    Execute in scope d3 selectAll using the given selector and return d3 selection result. Roughly
11833
    the same as:
11834
    ```js
11835
    d3.select('#chart-id').selectAll(selector);
11836
    ```
11837
    This function is **not chainable** since it does not return a chart instance; however the d3
11838
    selection result can be chained to d3 function calls.
11839
11840
    **/
11841
    _chart.selectAll = function (s) {
11842
        return _root ? _root.selectAll(s) : null;
11843
    };
11844
11845
    /**
11846
     #### .anchor([anchorChart|anchorSelector|anchorNode], [chartGroup])
11847
     Set the svg root to either be an existing chart's root; or any valid [d3 single
11848
     selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying a dom
11849
     block element such as a div; or a dom element or d3 selection. Optionally registers the chart
11850
     within the chartGroup. This class is called internally on chart initialization, but be called
11851
     again to relocate the chart. However, it will orphan any previously created SVG elements.
11852
    **/
11853
    _chart.anchor = function (a, chartGroup) {
11854
        if (!arguments.length) {
11855
            return _anchor;
11856
        }
11857
        if (dc.instanceOfChart(a)) {
11858
            _anchor = a.anchor();
11859
            _root = a.root();
11860
            _isChild = true;
11861
        } else {
11862
            _anchor = a;
11863
            _root = d3.select(_anchor);
11864
            _root.classed(dc.constants.CHART_CLASS, true);
11865
            dc.registerChart(_chart, chartGroup);
11866
            _isChild = false;
11867
        }
11868
        _chartGroup = chartGroup;
11869
        return _chart;
11870
    };
11871
11872
    /**
11873
    #### .anchorName()
11874
    Returns the dom id for the chart's anchored location.
11875
11876
    **/
11877
    _chart.anchorName = function () {
11878
        var a = _chart.anchor();
11879
        if (a && a.id) {
11880
            return a.id;
11881
        }
11882
        if (a && a.replace) {
11883
            return a.replace('#', '');
11884
        }
11885
        return 'dc-chart' + _chart.chartID();
11886
    };
11887
11888
    /**
11889
    #### .root([rootElement])
11890
    Returns the root element where a chart resides. Usually it will be the parent div element where
11891
    the svg was created. You can also pass in a new root element however this is usually handled by
11892
    dc internally. Resetting the root element on a chart outside of dc internals may have
11893
    unexpected consequences.
11894
11895
    **/
11896
    _chart.root = function (r) {
11897
        if (!arguments.length) {
11898
            return _root;
11899
        }
11900
        _root = r;
11901
        return _chart;
11902
    };
11903
11904
    /**
11905
    #### .svg([svgElement])
11906
    Returns the top svg element for this specific chart. You can also pass in a new svg element,
11907
    however this is usually handled by dc internally. Resetting the svg element on a chart outside
11908
    of dc internals may have unexpected consequences.
11909
11910
    **/
11911
    _chart.svg = function (_) {
11912
        if (!arguments.length) {
11913
            return _svg;
11914
        }
11915
        _svg = _;
11916
        return _chart;
11917
    };
11918
11919
    /**
11920
    #### .resetSvg()
11921
    Remove the chart's SVG elements from the dom and recreate the container SVG element.
11922
    **/
11923
    _chart.resetSvg = function () {
11924
        _chart.select('svg').remove();
11925
        return generateSvg();
11926
    };
11927
11928
    function generateSvg() {
11929
        _svg = _chart.root().append('svg')
11930
            .attr('width', _chart.width())
11931
            .attr('height', _chart.height());
11932
        return _svg;
11933
    }
11934
11935
    /**
11936
    #### .filterPrinter([filterPrinterFunction])
11937
    Set or get the filter printer function. The filter printer function is used to generate human
11938
    friendly text for filter value(s) associated with the chart instance. By default dc charts use a
11939
    default filter printer `dc.printers.filter` that provides simple printing support for both
11940
    single value and ranged filters.
11941
11942
    **/
11943
    _chart.filterPrinter = function (_) {
11944
        if (!arguments.length) {
11945
            return _filterPrinter;
11946
        }
11947
        _filterPrinter = _;
11948
        return _chart;
11949
    };
11950
11951
    /**
11952
    #### .turnOnControls() & .turnOffControls()
11953
    Turn on/off optional control elements within the root element. dc currently supports the
11954
    following html control elements.
11955
11956
    * root.selectAll('.reset') - elements are turned on if the chart has an active filter. This type
11957
     of control element is usually used to store a reset link to allow user to reset filter on a
11958
     certain chart. This element will be turned off automatically if the filter is cleared.
11959
    * root.selectAll('.filter') elements are turned on if the chart has an active filter. The text
11960
     content of this element is then replaced with the current filter value using the filter printer
11961
     function. This type of element will be turned off automatically if the filter is cleared.
11962
11963
    **/
11964
    _chart.turnOnControls = function () {
11965
        if (_root) {
11966
            _chart.selectAll('.reset').style('display', null);
11967
            _chart.selectAll('.filter').text(_filterPrinter(_chart.filters())).style('display', null);
11968
        }
11969
        return _chart;
11970
    };
11971
11972
    _chart.turnOffControls = function () {
11973
        if (_root) {
11974
            _chart.selectAll('.reset').style('display', 'none');
11975
            _chart.selectAll('.filter').style('display', 'none').text(_chart.filter());
11976
        }
11977
        return _chart;
11978
    };
11979
11980
    /**
11981
    #### .transitionDuration([duration])
11982
    Set or get the animation transition duration(in milliseconds) for this chart instance. Default
11983
    duration is 750ms.
11984
11985
    **/
11986
    _chart.transitionDuration = function (d) {
11987
        if (!arguments.length) {
11988
            return _transitionDuration;
11989
        }
11990
        _transitionDuration = d;
11991
        return _chart;
11992
    };
11993
11994
    _chart._mandatoryAttributes = function (_) {
11995
        if (!arguments.length) {
11996
            return _mandatoryAttributes;
11997
        }
11998
        _mandatoryAttributes = _;
11999
        return _chart;
12000
    };
12001
12002
    function checkForMandatoryAttributes(a) {
12003
        if (!_chart[a] || !_chart[a]()) {
12004
            throw new dc.errors.InvalidStateException('Mandatory attribute chart.' + a +
12005
                                                      ' is missing on chart[#' + _chart.anchorName() + ']');
12006
        }
12007
    }
12008
12009
    /**
12010
    #### .render()
12011
    Invoking this method will force the chart to re-render everything from scratch. Generally it
12012
    should only be used to render the chart for the first time on the page or if you want to make
12013
    sure everything is redrawn from scratch instead of relying on the default incremental redrawing
12014
    behaviour.
12015
12016
    **/
12017
    _chart.render = function () {
12018
        _listeners.preRender(_chart);
12019
12020
        if (_mandatoryAttributes) {
12021
            _mandatoryAttributes.forEach(checkForMandatoryAttributes);
12022
        }
12023
12024
        var result = _chart._doRender();
12025
12026
        if (_legend) {
12027
            _legend.render();
12028
        }
12029
12030
        _chart._activateRenderlets('postRender');
12031
12032
        return result;
12033
    };
12034
12035
    _chart._activateRenderlets = function (event) {
12036
        _listeners.pretransition(_chart);
12037
        if (_chart.transitionDuration() > 0 && _svg) {
12038
            _svg.transition().duration(_chart.transitionDuration())
12039
                .each('end', function () {
12040
                    _listeners['renderlet'](_chart);
12041
                    if (event) {
12042
                        _listeners[event](_chart);
12043
                    }
12044
                });
12045
        } else {
12046
            _listeners['renderlet'](_chart);
12047
            if (event) {
12048
                _listeners[event](_chart);
12049
            }
12050
        }
12051
    };
12052
12053
    /**
12054
    #### .redraw()
12055
    Calling redraw will cause the chart to re-render data changes incrementally. If there is no
12056
    change in the underlying data dimension then calling this method will have no effect on the
12057
    chart. Most chart interaction in dc will automatically trigger this method through internal
12058
    events (in particular [dc.redrawAll](#dcredrawallchartgroup)); therefore, you only need to
12059
    manually invoke this function if data is manipulated outside of dc's control (for example if
12060
    data is loaded in the background using `crossfilter.add()`).
12061
12062
    **/
12063
    _chart.redraw = function () {
12064
        _listeners.preRedraw(_chart);
12065
12066
        var result = _chart._doRedraw();
12067
12068
        if (_legend) {
12069
            _legend.render();
12070
        }
12071
12072
        _chart._activateRenderlets('postRedraw');
12073
12074
        return result;
12075
    };
12076
12077
    _chart.redrawGroup = function () {
12078
        dc.redrawAll(_chart.chartGroup());
12079
    };
12080
12081
    _chart.renderGroup = function () {
12082
        dc.renderAll(_chart.chartGroup());
12083
    };
12084
12085
    _chart._invokeFilteredListener = function (f) {
12086
        if (f !== undefined) {
12087
            _listeners.filtered(_chart, f);
12088
        }
12089
    };
12090
12091
    _chart._invokeZoomedListener = function () {
12092
        _listeners.zoomed(_chart);
12093
    };
12094
12095
    var _hasFilterHandler = function (filters, filter) {
12096
        if (filter === null || typeof(filter) === 'undefined') {
12097
            return filters.length > 0;
12098
        }
12099
        return filters.some(function (f) {
12100
            return filter <= f && filter >= f;
12101
        });
12102
    };
12103
12104
    /**
12105
    #### .hasFilterHandler([function])
12106
    Set or get the has filter handler. The has filter handler is a function that checks to see if
12107
    the chart's current filters include a specific filter.  Using a custom has filter handler allows
12108
    you to change the way filters are checked for and replaced.
12109
12110
    ```js
12111
    // default has filter handler
12112
    function (filters, filter) {
12113
        if (filter === null || typeof(filter) === 'undefined') {
12114
            return filters.length > 0;
12115
        }
12116
        return filters.some(function (f) {
12117
            return filter <= f && filter >= f;
12118
        });
12119
    }
12120
12121
    // custom filter handler (no-op)
12122
    chart.hasFilterHandler(function(filters, filter) {
12123
        return false;
12124
    });
12125
    ```
12126
    **/
12127
    _chart.hasFilterHandler = function (_) {
12128
        if (!arguments.length) {
12129
            return _hasFilterHandler;
12130
        }
12131
        _hasFilterHandler = _;
12132
        return _chart;
12133
    };
12134
12135
    /**
12136
    #### .hasFilter([filter])
12137
    Check whether any active filter or a specific filter is associated with particular chart instance.
12138
    This function is **not chainable**.
12139
12140
    **/
12141
    _chart.hasFilter = function (filter) {
12142
        return _hasFilterHandler(_filters, filter);
12143
    };
12144
12145
    var _removeFilterHandler = function (filters, filter) {
12146
        for (var i = 0; i < filters.length; i++) {
12147
            if (filters[i] <= filter && filters[i] >= filter) {
12148
                filters.splice(i, 1);
12149
                break;
12150
            }
12151
        }
12152
        return filters;
12153
    };
12154
12155
    /**
12156
    #### .removeFilterHandler([function])
12157
    Set or get the remove filter handler. The remove filter handler is a function that removes a
12158
    filter from the chart's current filters. Using a custom remove filter handler allows you to
12159
    change how filters are removed or perform additional work when removing a filter, e.g. when
12160
    using a filter server other than crossfilter.
12161
12162
    Any changes should modify the `filters` array argument and return that array.
12163
12164
    ```js
12165
    // default remove filter handler
12166
    function (filters, filter) {
12167
        for (var i = 0; i < filters.length; i++) {
12168
            if (filters[i] <= filter && filters[i] >= filter) {
12169
                filters.splice(i, 1);
12170
                break;
12171
            }
12172
        }
12173
        return filters;
12174
    }
12175
12176
    // custom filter handler (no-op)
12177
    chart.removeFilterHandler(function(filters, filter) {
12178
        return filters;
12179
    });
12180
    ```
12181
    **/
12182
    _chart.removeFilterHandler = function (_) {
12183
        if (!arguments.length) {
12184
            return _removeFilterHandler;
12185
        }
12186
        _removeFilterHandler = _;
12187
        return _chart;
12188
    };
12189
12190
    var _addFilterHandler = function (filters, filter) {
12191
        filters.push(filter);
12192
        return filters;
12193
    };
12194
12195
    /**
12196
    #### .addFilterHandler([function])
12197
    Set or get the add filter handler. The add filter handler is a function that adds a filter to
12198
    the chart's filter list. Using a custom add filter handler allows you to change the way filters
12199
    are added or perform additional work when adding a filter, e.g. when using a filter server other
12200
    than crossfilter.
12201
12202
    Any changes should modify the `filters` array argument and return that array.
12203
12204
    ```js
12205
    // default add filter handler
12206
    function (filters, filter) {
12207
        filters.push(filter);
12208
        return filters;
12209
    }
12210
12211
    // custom filter handler (no-op)
12212
    chart.addFilterHandler(function(filters, filter) {
12213
        return filters;
12214
    });
12215
    ```
12216
    **/
12217
    _chart.addFilterHandler = function (_) {
12218
        if (!arguments.length) {
12219
            return _addFilterHandler;
12220
        }
12221
        _addFilterHandler = _;
12222
        return _chart;
12223
    };
12224
12225
    var _resetFilterHandler = function (filters) {
0 ignored issues
show
Unused Code introduced by
The parameter filters is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
12226
        return [];
12227
    };
12228
12229
    /**
12230
    #### .resetFilterHandler([function])
12231
    Set or get the reset filter handler. The reset filter handler is a function that resets the
12232
    chart's filter list by returning a new list. Using a custom reset filter handler allows you to
12233
    change the way filters are reset, or perform additional work when resetting the filters,
12234
    e.g. when using a filter server other than crossfilter.
12235
12236
    This function should return an array.
12237
12238
    ```js
12239
    // default remove filter handler
12240
    function (filters) {
12241
        return [];
12242
    }
12243
12244
    // custom filter handler (no-op)
12245
    chart.resetFilterHandler(function(filters) {
12246
        return filters;
12247
    });
12248
    ```
12249
    **/
12250
    _chart.resetFilterHandler = function (_) {
12251
        if (!arguments.length) {
12252
            return _resetFilterHandler;
12253
        }
12254
        _resetFilterHandler = _;
12255
        return _chart;
12256
    };
12257
12258
    function applyFilters() {
12259
        if (_chart.dimension() && _chart.dimension().filter) {
12260
            var fs = _filterHandler(_chart.dimension(), _filters);
12261
            _filters = fs ? fs : _filters;
12262
        }
12263
    }
12264
12265
    _chart.replaceFilter = function (_) {
12266
        _filters = [];
12267
        _chart.filter(_);
12268
    };
12269
12270
    /**
12271
    #### .filter([filterValue])
12272
    Filter the chart by the given value or return the current filter if the input parameter is missing.
12273
    ```js
12274
    // filter by a single string
12275
    chart.filter('Sunday');
12276
    // filter by a single age
12277
    chart.filter(18);
12278
    ```
12279
    **/
12280
    _chart.filter = function (_) {
12281
        if (!arguments.length) {
12282
            return _filters.length > 0 ? _filters[0] : null;
12283
        }
12284
        if (_ instanceof Array && _[0] instanceof Array && !_.isFiltered) {
12285
            _[0].forEach(function (d) {
12286
                if (_chart.hasFilter(d)) {
12287
                    _removeFilterHandler(_filters, d);
12288
                } else {
12289
                    _addFilterHandler(_filters, d);
12290
                }
12291
            });
12292
        } else if (_ === null) {
12293
            _filters = _resetFilterHandler(_filters);
12294
        } else {
12295
            if (_chart.hasFilter(_)) {
12296
                _removeFilterHandler(_filters, _);
12297
            } else {
12298
                _addFilterHandler(_filters, _);
12299
            }
12300
        }
12301
        applyFilters();
12302
        _chart._invokeFilteredListener(_);
12303
12304
        if (_root !== null && _chart.hasFilter()) {
12305
            _chart.turnOnControls();
12306
        } else {
12307
            _chart.turnOffControls();
12308
        }
12309
12310
        return _chart;
12311
    };
12312
12313
    /**
12314
    #### .filters()
12315
    Returns all current filters. This method does not perform defensive cloning of the internal
12316
    filter array before returning, therefore any modification of the returned array will effect the
12317
    chart's internal filter storage.
12318
12319
    **/
12320
    _chart.filters = function () {
12321
        return _filters;
12322
    };
12323
12324
    _chart.highlightSelected = function (e) {
12325
        d3.select(e).classed(dc.constants.SELECTED_CLASS, true);
12326
        d3.select(e).classed(dc.constants.DESELECTED_CLASS, false);
12327
    };
12328
12329
    _chart.fadeDeselected = function (e) {
12330
        d3.select(e).classed(dc.constants.SELECTED_CLASS, false);
12331
        d3.select(e).classed(dc.constants.DESELECTED_CLASS, true);
12332
    };
12333
12334
    _chart.resetHighlight = function (e) {
12335
        d3.select(e).classed(dc.constants.SELECTED_CLASS, false);
12336
        d3.select(e).classed(dc.constants.DESELECTED_CLASS, false);
12337
    };
12338
12339
    /**
12340
    #### .onClick(datum)
12341
    This function is passed to d3 as the onClick handler for each chart. The default behavior is to
12342
    filter on the clicked datum (passed to the callback) and redraw the chart group.
12343
    **/
12344
    _chart.onClick = function (d) {
12345
        var filter = _chart.keyAccessor()(d);
12346
        dc.events.trigger(function () {
12347
            _chart.filter(filter);
12348
            _chart.redrawGroup();
12349
        });
12350
    };
12351
12352
    /**
12353
    #### .filterHandler([function])
12354
    Set or get the filter handler. The filter handler is a function that performs the filter action
12355
    on a specific dimension. Using a custom filter handler allows you to perform additional logic
12356
    before or after filtering.
12357
12358
    ```js
12359
    // default filter handler
12360
    function(dimension, filter){
12361
        dimension.filter(filter); // perform filtering
12362
        return filter; // return the actual filter value
12363
    }
12364
12365
    // custom filter handler
12366
    chart.filterHandler(function(dimension, filter){
12367
        var newFilter = filter + 10;
12368
        dimension.filter(newFilter);
12369
        return newFilter; // set the actual filter value to the new value
12370
    });
12371
    ```
12372
12373
    **/
12374
    _chart.filterHandler = function (_) {
12375
        if (!arguments.length) {
12376
            return _filterHandler;
12377
        }
12378
        _filterHandler = _;
12379
        return _chart;
12380
    };
12381
12382
    // abstract function stub
12383
    _chart._doRender = function () {
12384
        // do nothing in base, should be overridden by sub-function
12385
        return _chart;
12386
    };
12387
12388
    _chart._doRedraw = function () {
12389
        // do nothing in base, should be overridden by sub-function
12390
        return _chart;
12391
    };
12392
12393
    _chart.legendables = function () {
12394
        // do nothing in base, should be overridden by sub-function
12395
        return [];
12396
    };
12397
12398
    _chart.legendHighlight = function () {
12399
        // do nothing in base, should be overridden by sub-function
12400
    };
12401
12402
    _chart.legendReset = function () {
12403
        // do nothing in base, should be overridden by sub-function
12404
    };
12405
12406
    _chart.legendToggle = function () {
12407
        // do nothing in base, should be overriden by sub-function
12408
    };
12409
12410
    _chart.isLegendableHidden = function () {
12411
        // do nothing in base, should be overridden by sub-function
12412
        return false;
12413
    };
12414
12415
    /**
12416
    #### .keyAccessor([keyAccessorFunction])
12417
    Set or get the key accessor function. The key accessor function is used to retrieve the key
12418
    value from the crossfilter group. Key values are used differently in different charts, for
12419
    example keys correspond to slices in a pie chart and x axis positions in a grid coordinate chart.
12420
    ```js
12421
    // default key accessor
12422
    chart.keyAccessor(function(d) { return d.key; });
12423
    // custom key accessor for a multi-value crossfilter reduction
12424
    chart.keyAccessor(function(p) { return p.value.absGain; });
12425
    ```
12426
12427
    **/
12428
    _chart.keyAccessor = function (_) {
12429
        if (!arguments.length) {
12430
            return _keyAccessor;
12431
        }
12432
        _keyAccessor = _;
12433
        return _chart;
12434
    };
12435
12436
    /**
12437
    #### .valueAccessor([valueAccessorFunction])
12438
    Set or get the value accessor function. The value accessor function is used to retrieve the
12439
    value from the crossfilter group. Group values are used differently in different charts, for
12440
    example values correspond to slice sizes in a pie chart and y axis positions in a grid
12441
    coordinate chart.
12442
    ```js
12443
    // default value accessor
12444
    chart.valueAccessor(function(d) { return d.value; });
12445
    // custom value accessor for a multi-value crossfilter reduction
12446
    chart.valueAccessor(function(p) { return p.value.percentageGain; });
12447
    ```
12448
12449
    **/
12450
    _chart.valueAccessor = function (_) {
12451
        if (!arguments.length) {
12452
            return _valueAccessor;
12453
        }
12454
        _valueAccessor = _;
12455
        return _chart;
12456
    };
12457
12458
    /**
12459
    #### .label([labelFunction])
12460
    Set or get the label function. The chart class will use this function to render labels for each
12461
    child element in the chart, e.g. slices in a pie chart or bubbles in a bubble chart. Not every
12462
    chart supports the label function for example bar chart and line chart do not use this function
12463
    at all.
12464
    ```js
12465
    // default label function just return the key
12466
    chart.label(function(d) { return d.key; });
12467
    // label function has access to the standard d3 data binding and can get quite complicated
12468
    chart.label(function(d) { return d.data.key + '(' + Math.floor(d.data.value / all.value() * 100) + '%)'; });
12469
    ```
12470
12471
    **/
12472
    _chart.label = function (_) {
12473
        if (!arguments.length) {
12474
            return _label;
12475
        }
12476
        _label = _;
12477
        _renderLabel = true;
12478
        return _chart;
12479
    };
12480
12481
    /**
12482
    #### .renderLabel(boolean)
12483
    Turn on/off label rendering
12484
12485
    **/
12486
    _chart.renderLabel = function (_) {
12487
        if (!arguments.length) {
12488
            return _renderLabel;
12489
        }
12490
        _renderLabel = _;
12491
        return _chart;
12492
    };
12493
12494
    /**
12495
    #### .title([titleFunction])
12496
    Set or get the title function. The chart class will use this function to render the svg title
12497
    (usually interpreted by browser as tooltips) for each child element in the chart, e.g. a slice
12498
    in a pie chart or a bubble in a bubble chart. Almost every chart supports the title function;
12499
    however in grid coordinate charts you need to turn off the brush in order to see titles, because
12500
    otherwise the brush layer will block tooltip triggering.
12501
    ```js
12502
    // default title function just return the key
12503
    chart.title(function(d) { return d.key + ': ' + d.value; });
12504
    // title function has access to the standard d3 data binding and can get quite complicated
12505
    chart.title(function(p) {
12506
        return p.key.getFullYear()
12507
            + '\n'
12508
            + 'Index Gain: ' + numberFormat(p.value.absGain) + '\n'
12509
            + 'Index Gain in Percentage: ' + numberFormat(p.value.percentageGain) + '%\n'
12510
            + 'Fluctuation / Index Ratio: ' + numberFormat(p.value.fluctuationPercentage) + '%';
12511
    });
12512
    ```
12513
12514
    **/
12515
    _chart.title = function (_) {
12516
        if (!arguments.length) {
12517
            return _title;
12518
        }
12519
        _title = _;
12520
        return _chart;
12521
    };
12522
12523
    /**
12524
    #### .renderTitle(boolean)
12525
    Turn on/off title rendering, or return the state of the render title flag if no arguments are
12526
    given.
12527
12528
    **/
12529
    _chart.renderTitle = function (_) {
12530
        if (!arguments.length) {
12531
            return _renderTitle;
12532
        }
12533
        _renderTitle = _;
12534
        return _chart;
12535
    };
12536
12537
    /**
12538
    #### .renderlet(renderletFunction)
12539
    A renderlet is similar to an event listener on rendering event. Multiple renderlets can be added
12540
    to an individual chart.  Each time a chart is rerendered or redrawn the renderlets are invoked
12541
    right after the chart finishes its transitions, giving you a way to modify the svg
12542
    elements. Renderlet functions take the chart instance as the only input parameter and you can
12543
    use the dc API or use raw d3 to achieve pretty much any effect.
12544
12545
    @Deprecated - Use [Listeners](#Listeners) with a 'renderlet' prefix
12546
    Generates a random key for the renderlet, which makes it hard to remove.
12547
    ```js
12548
    // do this instead of .renderlet(function(chart) { ... })
12549
    chart.on("renderlet", function(chart){
12550
        // mix of dc API and d3 manipulation
12551
        chart.select('g.y').style('display', 'none');
12552
        // its a closure so you can also access other chart variable available in the closure scope
12553
        moveChart.filter(chart.filter());
12554
    });
12555
    ```
12556
12557
    **/
12558
    _chart.renderlet = dc.logger.deprecate(function (_) {
12559
        _chart.on('renderlet.' + dc.utils.uniqueId(), _);
12560
        return _chart;
12561
    }, 'chart.renderlet has been deprecated.  Please use chart.on("renderlet.<renderletKey>", renderletFunction)');
12562
12563
    /**
12564
    #### .chartGroup([group])
12565
    Get or set the chart group to which this chart belongs. Chart groups are rendered or redrawn
12566
    together since it is expected they share the same underlying crossfilter data set.
12567
    **/
12568
    _chart.chartGroup = function (_) {
12569
        if (!arguments.length) {
12570
            return _chartGroup;
12571
        }
12572
        if (!_isChild) {
12573
            dc.deregisterChart(_chart, _chartGroup);
12574
        }
12575
        _chartGroup = _;
12576
        if (!_isChild) {
12577
            dc.registerChart(_chart, _chartGroup);
12578
        }
12579
        return _chart;
12580
    };
12581
12582
    /**
12583
    #### .expireCache()
12584
    Expire the internal chart cache. dc charts cache some data internally on a per chart basis to
12585
    speed up rendering and avoid unnecessary calculation; however it might be useful to clear the
12586
    cache if you have changed state which will affect rendering.  For example if you invoke the
12587
    `crossfilter.add` function or reset group or dimension after rendering it is a good idea to
12588
    clear the cache to make sure charts are rendered properly.
12589
12590
    **/
12591
    _chart.expireCache = function () {
12592
        // do nothing in base, should be overridden by sub-function
12593
        return _chart;
12594
    };
12595
12596
    /**
12597
    #### .legend([dc.legend])
12598
    Attach a dc.legend widget to this chart. The legend widget will automatically draw legend labels
12599
    based on the color setting and names associated with each group.
12600
12601
    ```js
12602
    chart.legend(dc.legend().x(400).y(10).itemHeight(13).gap(5))
12603
    ```
12604
12605
    **/
12606
    _chart.legend = function (l) {
12607
        if (!arguments.length) {
12608
            return _legend;
12609
        }
12610
        _legend = l;
12611
        _legend.parent(_chart);
12612
        return _chart;
12613
    };
12614
12615
    /**
12616
    #### .chartID()
12617
    Returns the internal numeric ID of the chart.
12618
    **/
12619
    _chart.chartID = function () {
12620
        return _chart.__dcFlag__;
12621
    };
12622
12623
    /**
12624
    #### .options(optionsObject)
12625
    Set chart options using a configuration object. Each key in the object will cause the method of
12626
    the same name to be called with the value to set that attribute for the chart.
12627
12628
    Example:
12629
    ```
12630
    chart.options({dimension: myDimension, group: myGroup});
12631
    ```
12632
    **/
12633
    _chart.options = function (opts) {
12634
        var applyOptions = [
12635
            'anchor',
12636
            'group',
12637
            'xAxisLabel',
12638
            'yAxisLabel',
12639
            'stack',
12640
            'title',
12641
            'point',
12642
            'getColor',
12643
            'overlayGeoJson'
12644
        ];
12645
12646
        for (var o in opts) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
12647
            if (typeof(_chart[o]) === 'function') {
12648
                if (opts[o] instanceof Array && applyOptions.indexOf(o) !== -1) {
12649
                    _chart[o].apply(_chart, opts[o]);
12650
                } else {
12651
                    _chart[o].call(_chart, opts[o]);
12652
                }
12653
            } else {
12654
                dc.logger.debug('Not a valid option setter name: ' + o);
12655
            }
12656
        }
12657
        return _chart;
12658
    };
12659
12660
    /**
12661
    ## Listeners
12662
    All dc chart instance supports the following listeners.
12663
12664
    #### .on('renderlet', function(chart, filter){...})
12665
    This listener function will be invoked after transitions after redraw and render. Replaces the
12666
    deprecated `.renderlet()` method.
12667
12668
    #### .on('pretransition', function(chart, filter){...})
12669
    Like `.on('renderlet', ...)` but the event is fired before transitions start.
12670
12671
    #### .on('preRender', function(chart){...})
12672
    This listener function will be invoked before chart rendering.
12673
12674
    #### .on('postRender', function(chart){...})
12675
    This listener function will be invoked after chart finish rendering including all renderlets' logic.
12676
12677
    #### .on('preRedraw', function(chart){...})
12678
    This listener function will be invoked before chart redrawing.
12679
12680
    #### .on('postRedraw', function(chart){...})
12681
    This listener function will be invoked after chart finish redrawing including all renderlets' logic.
12682
12683
    #### .on('filtered', function(chart, filter){...})
12684
    This listener function will be invoked after a filter is applied, added or removed.
12685
12686
    #### .on('zoomed', function(chart, filter){...})
12687
    This listener function will be invoked after a zoom is triggered.
12688
12689
    **/
12690
    _chart.on = function (event, listener) {
12691
        _listeners.on(event, listener);
12692
        return _chart;
12693
    };
12694
12695
    return _chart;
12696
};
12697
12698
/**
12699
## Margin Mixin
12700
Margin is a mixin that provides margin utility functions for both the Row Chart and Coordinate Grid
12701
Charts.
12702
12703
**/
12704
dc.marginMixin = function (_chart) {
12705
    var _margin = {top: 10, right: 50, bottom: 30, left: 30};
12706
12707
    /**
12708
    #### .margins([margins])
12709
    Get or set the margins for a particular coordinate grid chart instance. The margins is stored as
12710
    an associative Javascript array. Default margins: {top: 10, right: 50, bottom: 30, left: 30}.
12711
12712
    The margins can be accessed directly from the getter.
12713
    ```js
12714
    var leftMargin = chart.margins().left; // 30 by default
12715
    chart.margins().left = 50;
12716
    leftMargin = chart.margins().left; // now 50
12717
    ```
12718
12719
    **/
12720
    _chart.margins = function (m) {
12721
        if (!arguments.length) {
12722
            return _margin;
12723
        }
12724
        _margin = m;
12725
        return _chart;
12726
    };
12727
12728
    _chart.effectiveWidth = function () {
12729
        return _chart.width() - _chart.margins().left - _chart.margins().right;
12730
    };
12731
12732
    _chart.effectiveHeight = function () {
12733
        return _chart.height() - _chart.margins().top - _chart.margins().bottom;
12734
    };
12735
12736
    return _chart;
12737
};
12738
12739
/**
12740
## Color Mixin
12741
The Color Mixin is an abstract chart functional class providing universal coloring support
12742
as a mix-in for any concrete chart implementation.
12743
12744
**/
12745
12746
dc.colorMixin = function (_chart) {
12747
    var _colors = d3.scale.category20c();
12748
    var _defaultAccessor = true;
12749
12750
    var _colorAccessor = function (d) { return _chart.keyAccessor()(d); };
12751
12752
    /**
12753
    #### .colors([colorScale])
12754
    Retrieve current color scale or set a new color scale. This methods accepts any function that
12755
    operates like a d3 scale. If not set the default is
12756
    `d3.scale.category20c()`.
12757
    ```js
12758
    // alternate categorical scale
12759
    chart.colors(d3.scale.category20b());
12760
12761
    // ordinal scale
12762
    chart.colors(d3.scale.ordinal().range(['red','green','blue']));
12763
    // convenience method, the same as above
12764
    chart.ordinalColors(['red','green','blue']);
12765
12766
    // set a linear scale
12767
    chart.linearColors(["#4575b4", "#ffffbf", "#a50026"]);
12768
    ```
12769
    **/
12770
    _chart.colors = function (_) {
12771
        if (!arguments.length) {
12772
            return _colors;
12773
        }
12774
        if (_ instanceof Array) {
12775
            _colors = d3.scale.quantize().range(_); // deprecated legacy support, note: this fails for ordinal domains
12776
        } else {
12777
            _colors = d3.functor(_);
12778
        }
12779
        return _chart;
12780
    };
12781
12782
    /**
12783
    #### .ordinalColors(r)
12784
    Convenience method to set the color scale to d3.scale.ordinal with range `r`.
12785
12786
    **/
12787
    _chart.ordinalColors = function (r) {
12788
        return _chart.colors(d3.scale.ordinal().range(r));
12789
    };
12790
12791
    /**
12792
    #### .linearColors(r)
12793
    Convenience method to set the color scale to an Hcl interpolated linear scale with range `r`.
12794
12795
    **/
12796
    _chart.linearColors = function (r) {
12797
        return _chart.colors(d3.scale.linear()
12798
                             .range(r)
12799
                             .interpolate(d3.interpolateHcl));
12800
    };
12801
12802
    /**
12803
    #### .colorAccessor([colorAccessorFunction])
12804
    Set or the get color accessor function. This function will be used to map a data point in a
12805
    crossfilter group to a color value on the color scale. The default function uses the key
12806
    accessor.
12807
    ```js
12808
    // default index based color accessor
12809
    .colorAccessor(function (d, i){return i;})
12810
    // color accessor for a multi-value crossfilter reduction
12811
    .colorAccessor(function (d){return d.value.absGain;})
12812
    ```
12813
    **/
12814
    _chart.colorAccessor = function (_) {
12815
        if (!arguments.length) {
12816
            return _colorAccessor;
12817
        }
12818
        _colorAccessor = _;
12819
        _defaultAccessor = false;
12820
        return _chart;
12821
    };
12822
12823
    // what is this?
12824
    _chart.defaultColorAccessor = function () {
12825
        return _defaultAccessor;
12826
    };
12827
12828
    /**
12829
    #### .colorDomain([domain])
12830
    Set or get the current domain for the color mapping function. The domain must be supplied as an
12831
    array.
12832
12833
    Note: previously this method accepted a callback function. Instead you may use a custom scale
12834
    set by `.colors`.
12835
12836
    **/
12837
    _chart.colorDomain = function (_) {
12838
        if (!arguments.length) {
12839
            return _colors.domain();
12840
        }
12841
        _colors.domain(_);
12842
        return _chart;
12843
    };
12844
12845
    /**
12846
    #### .calculateColorDomain()
12847
    Set the domain by determining the min and max values as retrieved by `.colorAccessor` over the
12848
    chart's dataset.
12849
12850
    **/
12851
    _chart.calculateColorDomain = function () {
12852
        var newDomain = [d3.min(_chart.data(), _chart.colorAccessor()),
12853
                         d3.max(_chart.data(), _chart.colorAccessor())];
12854
        _colors.domain(newDomain);
12855
        return _chart;
12856
    };
12857
12858
    /**
12859
    #### .getColor(d [, i])
12860
    Get the color for the datum d and counter i. This is used internally by charts to retrieve a color.
12861
12862
    **/
12863
    _chart.getColor = function (d, i) {
12864
        return _colors(_colorAccessor.call(this, d, i));
12865
    };
12866
12867
    /**
12868
     #### .colorCalculator([value])
12869
     Gets or sets chart.getColor.
12870
     **/
12871
    _chart.colorCalculator = function (_) {
12872
        if (!arguments.length) {
12873
            return _chart.getColor;
12874
        }
12875
        _chart.getColor = _;
12876
        return _chart;
12877
    };
12878
12879
    return _chart;
12880
};
12881
12882
/**
12883
## Coordinate Grid Mixin
12884
Includes: [Color Mixin](#color-mixin), [Margin Mixin](#margin-mixin), [Base Mixin](#base-mixin)
12885
12886
Coordinate Grid is an abstract base chart designed to support a number of coordinate grid based
12887
concrete chart types, e.g. bar chart, line chart, and bubble chart.
12888
12889
**/
12890
dc.coordinateGridMixin = function (_chart) {
12891
    var GRID_LINE_CLASS = 'grid-line';
12892
    var HORIZONTAL_CLASS = 'horizontal';
12893
    var VERTICAL_CLASS = 'vertical';
12894
    var Y_AXIS_LABEL_CLASS = 'y-axis-label';
12895
    var X_AXIS_LABEL_CLASS = 'x-axis-label';
12896
    var DEFAULT_AXIS_LABEL_PADDING = 12;
12897
12898
    _chart = dc.colorMixin(dc.marginMixin(dc.baseMixin(_chart)));
12899
12900
    _chart.colors(d3.scale.category10());
12901
    _chart._mandatoryAttributes().push('x');
12902
12903
    function zoomHandler () {
12904
        _refocused = true;
12905
        if (_zoomOutRestrict) {
12906
            _chart.x().domain(constrainRange(_chart.x().domain(), _xOriginalDomain));
12907
            if (_rangeChart) {
12908
                _chart.x().domain(constrainRange(_chart.x().domain(), _rangeChart.x().domain()));
12909
            }
12910
        }
12911
12912
        var domain = _chart.x().domain();
12913
        var domFilter = dc.filters.RangedFilter(domain[0], domain[1]);
12914
12915
        _chart.replaceFilter(domFilter);
12916
        _chart.rescale();
12917
        _chart.redraw();
12918
12919
        if (_rangeChart && !rangesEqual(_chart.filter(), _rangeChart.filter())) {
12920
            dc.events.trigger(function () {
12921
                _rangeChart.replaceFilter(domFilter);
12922
                _rangeChart.redraw();
12923
            });
12924
        }
12925
12926
        _chart._invokeZoomedListener();
12927
12928
        dc.events.trigger(function () {
12929
            _chart.redrawGroup();
12930
        }, dc.constants.EVENT_DELAY);
12931
12932
        _refocused = !rangesEqual(domain, _xOriginalDomain);
12933
    }
12934
12935
    var _parent;
12936
    var _g;
12937
    var _chartBodyG;
12938
12939
    var _x;
12940
    var _xOriginalDomain;
12941
    var _xAxis = d3.svg.axis().orient('bottom');
12942
    var _xUnits = dc.units.integers;
12943
    var _xAxisPadding = 0;
12944
    var _xElasticity = false;
12945
    var _xAxisLabel;
12946
    var _xAxisLabelPadding = 0;
12947
    var _lastXDomain;
12948
12949
    var _y;
12950
    var _yAxis = d3.svg.axis().orient('left');
12951
    var _yAxisPadding = 0;
12952
    var _yElasticity = false;
12953
    var _yAxisLabel;
12954
    var _yAxisLabelPadding = 0;
12955
12956
    var _brush = d3.svg.brush();
12957
    var _brushOn = true;
12958
    var _round;
12959
12960
    var _renderHorizontalGridLine = false;
12961
    var _renderVerticalGridLine = false;
12962
12963
    var _refocused = false;
12964
    var _unitCount;
12965
12966
    var _zoomScale = [1, Infinity];
12967
    var _zoomOutRestrict = true;
12968
12969
    var _zoom = d3.behavior.zoom().on('zoom', zoomHandler);
12970
    var _nullZoom = d3.behavior.zoom().on('zoom', null);
12971
    var _hasBeenMouseZoomable = false;
12972
12973
    var _rangeChart;
12974
    var _focusChart;
12975
12976
    var _mouseZoomable = false;
12977
    var _clipPadding = 0;
12978
12979
    var _outerRangeBandPadding = 0.5;
12980
    var _rangeBandPadding = 0;
12981
12982
    var _useRightYAxis = false;
12983
12984
    _chart.rescale = function () {
12985
        _unitCount = undefined;
12986
    };
12987
12988
    /**
12989
    #### .rangeChart([chart])
12990
    Get or set the range selection chart associated with this instance. Setting the range selection
12991
    chart using this function will automatically update its selection brush when the current chart
12992
    zooms in. In return the given range chart will also automatically attach this chart as its focus
12993
    chart hence zoom in when range brush updates. See the [Nasdaq 100
12994
    Index](http://dc-js.github.com/dc.js/) example for this effect in action.
12995
12996
    **/
12997
    _chart.rangeChart = function (_) {
12998
        if (!arguments.length) {
12999
            return _rangeChart;
13000
        }
13001
        _rangeChart = _;
13002
        _rangeChart.focusChart(_chart);
13003
        return _chart;
13004
    };
13005
13006
    /**
13007
    #### .zoomScale([extent])
13008
    Get or set the scale extent for mouse zooms.
13009
13010
    **/
13011
    _chart.zoomScale = function (_) {
13012
        if (!arguments.length) {
13013
            return _zoomScale;
13014
        }
13015
        _zoomScale = _;
13016
        return _chart;
13017
    };
13018
13019
    /**
13020
    #### .zoomOutRestrict([true/false])
13021
    Get or set the zoom restriction for the chart. If true limits the zoom to origional domain of the chart.
13022
    **/
13023
    _chart.zoomOutRestrict = function (r) {
13024
        if (!arguments.length) {
13025
            return _zoomOutRestrict;
13026
        }
13027
        _zoomScale[0] = r ? 1 : 0;
13028
        _zoomOutRestrict = r;
13029
        return _chart;
13030
    };
13031
13032
    _chart._generateG = function (parent) {
13033
        if (parent === undefined) {
13034
            _parent = _chart.svg();
13035
        } else {
13036
            _parent = parent;
13037
        }
13038
13039
        _g = _parent.append('g');
13040
13041
        _chartBodyG = _g.append('g').attr('class', 'chart-body')
13042
            .attr('transform', 'translate(' + _chart.margins().left + ', ' + _chart.margins().top + ')')
13043
            .attr('clip-path', 'url(#' + getClipPathId() + ')');
13044
13045
        return _g;
13046
    };
13047
13048
    /**
13049
    #### .g([gElement])
13050
    Get or set the root g element. This method is usually used to retrieve the g element in order to
13051
    overlay custom svg drawing programatically. **Caution**: The root g element is usually generated
13052
    by dc.js internals, and resetting it might produce unpredictable result.
13053
13054
    **/
13055
    _chart.g = function (_) {
13056
        if (!arguments.length) {
13057
            return _g;
13058
        }
13059
        _g = _;
13060
        return _chart;
13061
    };
13062
13063
    /**
13064
    #### .mouseZoomable([boolean])
13065
    Set or get mouse zoom capability flag (default: false). When turned on the chart will be
13066
    zoomable using the mouse wheel. If the range selector chart is attached zooming will also update
13067
    the range selection brush on the associated range selector chart.
13068
13069
    **/
13070
    _chart.mouseZoomable = function (z) {
13071
        if (!arguments.length) {
13072
            return _mouseZoomable;
13073
        }
13074
        _mouseZoomable = z;
13075
        return _chart;
13076
    };
13077
13078
    /**
13079
    #### .chartBodyG()
13080
    Retrieve the svg group for the chart body.
13081
    **/
13082
    _chart.chartBodyG = function (_) {
13083
        if (!arguments.length) {
13084
            return _chartBodyG;
13085
        }
13086
        _chartBodyG = _;
13087
        return _chart;
13088
    };
13089
13090
    /**
13091
    #### .x([xScale]) - **mandatory**
13092
    Get or set the x scale. The x scale can be any d3
13093
    [quantitive scale](https://github.com/mbostock/d3/wiki/Quantitative-Scales) or
13094
    [ordinal scale](https://github.com/mbostock/d3/wiki/Ordinal-Scales).
13095
    ```js
13096
    // set x to a linear scale
13097
    chart.x(d3.scale.linear().domain([-2500, 2500]))
13098
    // set x to a time scale to generate histogram
13099
    chart.x(d3.time.scale().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)]))
13100
    ```
13101
13102
    **/
13103
    _chart.x = function (_) {
13104
        if (!arguments.length) {
13105
            return _x;
13106
        }
13107
        _x = _;
13108
        _xOriginalDomain = _x.domain();
13109
        return _chart;
13110
    };
13111
13112
    _chart.xOriginalDomain = function () {
13113
        return _xOriginalDomain;
13114
    };
13115
13116
    /**
13117
    #### .xUnits([xUnits function])
13118
    Set or get the xUnits function. The coordinate grid chart uses the xUnits function to calculate
13119
    the number of data projections on x axis such as the number of bars for a bar chart or the
13120
    number of dots for a line chart. This function is expected to return a Javascript array of all
13121
    data points on x axis, or the number of points on the axis. [d3 time range functions
13122
    d3.time.days, d3.time.months, and
13123
    d3.time.years](https://github.com/mbostock/d3/wiki/Time-Intervals#aliases) are all valid xUnits
13124
    function. dc.js also provides a few units function, see the [Utilities](#utilities) section for
13125
    a list of built-in units functions. The default xUnits function is dc.units.integers.
13126
    ```js
13127
    // set x units to count days
13128
    chart.xUnits(d3.time.days);
13129
    // set x units to count months
13130
    chart.xUnits(d3.time.months);
13131
    ```
13132
    A custom xUnits function can be used as long as it follows the following interface:
13133
    ```js
13134
    // units in integer
13135
    function(start, end, xDomain) {
13136
        // simply calculates how many integers in the domain
13137
        return Math.abs(end - start);
13138
    };
13139
13140
    // fixed units
13141
    function(start, end, xDomain) {
13142
        // be aware using fixed units will disable the focus/zoom ability on the chart
13143
        return 1000;
13144
    };
13145
    ```
13146
13147
    **/
13148
    _chart.xUnits = function (_) {
13149
        if (!arguments.length) {
13150
            return _xUnits;
13151
        }
13152
        _xUnits = _;
13153
        return _chart;
13154
    };
13155
13156
    /**
13157
    #### .xAxis([xAxis])
13158
    Set or get the x axis used by a particular coordinate grid chart instance. This function is most
13159
    useful when x axis customization is required. The x axis in dc.js is an instance of a [d3
13160
    axis object](https://github.com/mbostock/d3/wiki/SVG-Axes#wiki-axis); therefore it supports any
13161
    valid d3 axis manipulation. **Caution**: The x axis is usually generated internally by dc;
13162
    resetting it may cause unexpected results.
13163
    ```js
13164
    // customize x axis tick format
13165
    chart.xAxis().tickFormat(function(v) {return v + '%';});
13166
    // customize x axis tick values
13167
    chart.xAxis().tickValues([0, 100, 200, 300]);
13168
    ```
13169
13170
    **/
13171
    _chart.xAxis = function (_) {
13172
        if (!arguments.length) {
13173
            return _xAxis;
13174
        }
13175
        _xAxis = _;
13176
        return _chart;
13177
    };
13178
13179
    /**
13180
    #### .elasticX([boolean])
13181
    Turn on/off elastic x axis behavior. If x axis elasticity is turned on, then the grid chart will
13182
    attempt to recalculate the x axis range whenever a redraw event is triggered.
13183
13184
    **/
13185
    _chart.elasticX = function (_) {
13186
        if (!arguments.length) {
13187
            return _xElasticity;
13188
        }
13189
        _xElasticity = _;
13190
        return _chart;
13191
    };
13192
13193
    /**
13194
    #### .xAxisPadding([padding])
13195
    Set or get x axis padding for the elastic x axis. The padding will be added to both end of the x
13196
    axis if elasticX is turned on; otherwise it is ignored.
13197
13198
    * padding can be an integer or percentage in string (e.g. '10%'). Padding can be applied to
13199
    number or date x axes.  When padding a date axis, an integer represents number of days being padded
13200
    and a percentage string will be treated the same as an integer.
13201
13202
    **/
13203
    _chart.xAxisPadding = function (_) {
13204
        if (!arguments.length) {
13205
            return _xAxisPadding;
13206
        }
13207
        _xAxisPadding = _;
13208
        return _chart;
13209
    };
13210
13211
    /**
13212
    #### .xUnitCount()
13213
    Returns the number of units displayed on the x axis using the unit measure configured by
13214
    .xUnits.
13215
    **/
13216
    _chart.xUnitCount = function () {
13217
        if (_unitCount === undefined) {
13218
            var units = _chart.xUnits()(_chart.x().domain()[0], _chart.x().domain()[1], _chart.x().domain());
13219
13220
            if (units instanceof Array) {
13221
                _unitCount = units.length;
13222
            } else {
13223
                _unitCount = units;
13224
            }
13225
        }
13226
13227
        return _unitCount;
0 ignored issues
show
Bug introduced by
The variable _unitCount does not seem to be initialized in case _unitCount === undefined on line 13217 is false. Are you sure this can never be the case?
Loading history...
13228
    };
13229
    /**
13230
     #### .useRightYAxis()
13231
     Gets or sets whether the chart should be drawn with a right axis instead of a left axis. When
13232
     used with a chart in a composite chart, allows both left and right Y axes to be shown on a
13233
     chart.
13234
     **/
13235
13236
    _chart.useRightYAxis = function (_) {
13237
        if (!arguments.length) {
13238
            return _useRightYAxis;
13239
        }
13240
        _useRightYAxis = _;
13241
        return _chart;
13242
    };
13243
13244
    /**
13245
    #### isOrdinal()
13246
    Returns true if the chart is using ordinal xUnits ([dc.units.ordinal](#dcunitsordinal)), or false
13247
    otherwise. Most charts behave differently with ordinal data and use the result of this method to
13248
    trigger the appropriate logic.
13249
    **/
13250
    _chart.isOrdinal = function () {
13251
        return _chart.xUnits() === dc.units.ordinal;
13252
    };
13253
13254
    _chart._useOuterPadding = function () {
13255
        return true;
13256
    };
13257
13258
    _chart._ordinalXDomain = function () {
13259
        var groups = _chart._computeOrderedGroups(_chart.data());
13260
        return groups.map(_chart.keyAccessor());
13261
    };
13262
13263
    function prepareXAxis(g) {
13264
        if (!_chart.isOrdinal()) {
13265
            if (_chart.elasticX()) {
13266
                _x.domain([_chart.xAxisMin(), _chart.xAxisMax()]);
13267
            }
13268
        }
13269
        else { // _chart.isOrdinal()
13270
            if (_chart.elasticX() || _x.domain().length === 0) {
13271
                _x.domain(_chart._ordinalXDomain());
13272
            }
13273
        }
13274
13275
        // has the domain changed?
13276
        var xdom = _x.domain();
13277
        if (!_lastXDomain || xdom.some(function (elem, i) { return elem !== _lastXDomain[i]; })) {
13278
            _chart.rescale();
13279
        }
13280
        _lastXDomain = xdom;
13281
13282
        // please can't we always use rangeBands for bar charts?
13283
        if (_chart.isOrdinal()) {
13284
            _x.rangeBands([0, _chart.xAxisLength()], _rangeBandPadding,
13285
                          _chart._useOuterPadding() ? _outerRangeBandPadding : 0);
13286
        } else {
13287
            _x.range([0, _chart.xAxisLength()]);
13288
        }
13289
13290
        _xAxis = _xAxis.scale(_chart.x());
13291
13292
        renderVerticalGridLines(g);
13293
    }
13294
13295
    _chart.renderXAxis = function (g) {
13296
        var axisXG = g.selectAll('g.x');
13297
13298
        if (axisXG.empty()) {
13299
            axisXG = g.append('g')
13300
                .attr('class', 'axis x')
13301
                .attr('transform', 'translate(' + _chart.margins().left + ',' + _chart._xAxisY() + ')');
13302
        }
13303
13304
        var axisXLab = g.selectAll('text.' + X_AXIS_LABEL_CLASS);
13305
        if (axisXLab.empty() && _chart.xAxisLabel()) {
13306
            axisXLab = g.append('text')
13307
                .attr('transform', 'translate(' + (_chart.margins().left + _chart.xAxisLength() / 2) + ',' +
13308
                    (_chart.height() - _xAxisLabelPadding) + ')')
13309
                .attr('class', X_AXIS_LABEL_CLASS)
13310
                .attr('text-anchor', 'middle')
13311
                .text(_chart.xAxisLabel());
13312
        }
13313
        if (_chart.xAxisLabel() && axisXLab.text() !== _chart.xAxisLabel()) {
13314
            axisXLab.text(_chart.xAxisLabel());
13315
        }
13316
13317
        dc.transition(axisXG, _chart.transitionDuration())
13318
            .call(_xAxis);
13319
    };
13320
13321
    function renderVerticalGridLines(g) {
13322
        var gridLineG = g.selectAll('g.' + VERTICAL_CLASS);
13323
13324
        if (_renderVerticalGridLine) {
13325
            if (gridLineG.empty()) {
13326
                gridLineG = g.insert('g', ':first-child')
13327
                    .attr('class', GRID_LINE_CLASS + ' ' + VERTICAL_CLASS)
13328
                    .attr('transform', 'translate(' + _chart.margins().left + ',' + _chart.margins().top + ')');
13329
            }
13330
13331
            var ticks = _xAxis.tickValues() ? _xAxis.tickValues() :
13332
                    (typeof _x.ticks === 'function' ? _x.ticks(_xAxis.ticks()[0]) : _x.domain());
13333
13334
            var lines = gridLineG.selectAll('line')
13335
                .data(ticks);
13336
13337
            // enter
13338
            var linesGEnter = lines.enter()
13339
                .append('line')
13340
                .attr('x1', function (d) {
13341
                    return _x(d);
13342
                })
13343
                .attr('y1', _chart._xAxisY() - _chart.margins().top)
13344
                .attr('x2', function (d) {
13345
                    return _x(d);
13346
                })
13347
                .attr('y2', 0)
13348
                .attr('opacity', 0);
13349
            dc.transition(linesGEnter, _chart.transitionDuration())
13350
                .attr('opacity', 1);
13351
13352
            // update
13353
            dc.transition(lines, _chart.transitionDuration())
13354
                .attr('x1', function (d) {
13355
                    return _x(d);
13356
                })
13357
                .attr('y1', _chart._xAxisY() - _chart.margins().top)
13358
                .attr('x2', function (d) {
13359
                    return _x(d);
13360
                })
13361
                .attr('y2', 0);
13362
13363
            // exit
13364
            lines.exit().remove();
13365
        }
13366
        else {
13367
            gridLineG.selectAll('line').remove();
13368
        }
13369
    }
13370
13371
    _chart._xAxisY = function () {
13372
        return (_chart.height() - _chart.margins().bottom);
13373
    };
13374
13375
    _chart.xAxisLength = function () {
13376
        return _chart.effectiveWidth();
13377
    };
13378
13379
    /**
13380
    #### .xAxisLabel([labelText, [, padding]])
13381
    Set or get the x axis label. If setting the label, you may optionally include additional padding to
13382
    the margin to make room for the label. By default the padded is set to 12 to accomodate the text height.
13383
    **/
13384
    _chart.xAxisLabel = function (_, padding) {
13385
        if (!arguments.length) {
13386
            return _xAxisLabel;
13387
        }
13388
        _xAxisLabel = _;
13389
        _chart.margins().bottom -= _xAxisLabelPadding;
13390
        _xAxisLabelPadding = (padding === undefined) ? DEFAULT_AXIS_LABEL_PADDING : padding;
13391
        _chart.margins().bottom += _xAxisLabelPadding;
13392
        return _chart;
13393
    };
13394
13395
    _chart._prepareYAxis = function (g) {
13396
        if (_y === undefined || _chart.elasticY()) {
13397
            _y = d3.scale.linear();
13398
            var min = _chart.yAxisMin() || 0,
13399
                max = _chart.yAxisMax() || 0;
13400
            _y.domain([min, max]).rangeRound([_chart.yAxisHeight(), 0]);
13401
        }
13402
13403
        _y.range([_chart.yAxisHeight(), 0]);
0 ignored issues
show
Bug introduced by
The variable _y does not seem to be initialized in case _y === undefined || _chart.elasticY() on line 13396 is false. Are you sure this can never be the case?
Loading history...
13404
        _yAxis = _yAxis.scale(_y);
13405
13406
        if (_useRightYAxis) {
13407
            _yAxis.orient('right');
13408
        }
13409
13410
        _chart._renderHorizontalGridLinesForAxis(g, _y, _yAxis);
13411
    };
13412
13413
    _chart.renderYAxisLabel = function (axisClass, text, rotation, labelXPosition) {
13414
        labelXPosition = labelXPosition || _yAxisLabelPadding;
13415
13416
        var axisYLab = _chart.g().selectAll('text.' + Y_AXIS_LABEL_CLASS + '.' + axisClass + '-label');
13417
        if (axisYLab.empty() && text) {
13418
13419
            var labelYPosition = (_chart.margins().top + _chart.yAxisHeight() / 2);
13420
            axisYLab = _chart.g().append('text')
13421
                .attr('transform', 'translate(' + labelXPosition + ',' + labelYPosition + '),rotate(' + rotation + ')')
13422
                .attr('class', Y_AXIS_LABEL_CLASS + ' ' + axisClass + '-label')
13423
                .attr('text-anchor', 'middle')
13424
                .text(text);
13425
        }
13426
        if (text && axisYLab.text() !== text) {
13427
            axisYLab.text(text);
13428
        }
13429
    };
13430
13431
    _chart.renderYAxisAt = function (axisClass, axis, position) {
13432
        var axisYG = _chart.g().selectAll('g.' + axisClass);
13433
        if (axisYG.empty()) {
13434
            axisYG = _chart.g().append('g')
13435
                .attr('class', 'axis ' + axisClass)
13436
                .attr('transform', 'translate(' + position + ',' + _chart.margins().top + ')');
13437
        }
13438
13439
        dc.transition(axisYG, _chart.transitionDuration()).call(axis);
13440
    };
13441
13442
    _chart.renderYAxis = function () {
13443
        var axisPosition = _useRightYAxis ? (_chart.width() - _chart.margins().right) : _chart._yAxisX();
13444
        _chart.renderYAxisAt('y', _yAxis, axisPosition);
13445
        var labelPosition = _useRightYAxis ? (_chart.width() - _yAxisLabelPadding) : _yAxisLabelPadding;
13446
        var rotation = _useRightYAxis ? 90 : -90;
13447
        _chart.renderYAxisLabel('y', _chart.yAxisLabel(), rotation, labelPosition);
13448
    };
13449
13450
    _chart._renderHorizontalGridLinesForAxis = function (g, scale, axis) {
13451
        var gridLineG = g.selectAll('g.' + HORIZONTAL_CLASS);
13452
13453
        if (_renderHorizontalGridLine) {
13454
            var ticks = axis.tickValues() ? axis.tickValues() : scale.ticks(axis.ticks()[0]);
13455
13456
            if (gridLineG.empty()) {
13457
                gridLineG = g.insert('g', ':first-child')
13458
                    .attr('class', GRID_LINE_CLASS + ' ' + HORIZONTAL_CLASS)
13459
                    .attr('transform', 'translate(' + _chart.margins().left + ',' + _chart.margins().top + ')');
13460
            }
13461
13462
            var lines = gridLineG.selectAll('line')
13463
                .data(ticks);
13464
13465
            // enter
13466
            var linesGEnter = lines.enter()
13467
                .append('line')
13468
                .attr('x1', 1)
13469
                .attr('y1', function (d) {
13470
                    return scale(d);
13471
                })
13472
                .attr('x2', _chart.xAxisLength())
13473
                .attr('y2', function (d) {
13474
                    return scale(d);
13475
                })
13476
                .attr('opacity', 0);
13477
            dc.transition(linesGEnter, _chart.transitionDuration())
13478
                .attr('opacity', 1);
13479
13480
            // update
13481
            dc.transition(lines, _chart.transitionDuration())
13482
                .attr('x1', 1)
13483
                .attr('y1', function (d) {
13484
                    return scale(d);
13485
                })
13486
                .attr('x2', _chart.xAxisLength())
13487
                .attr('y2', function (d) {
13488
                    return scale(d);
13489
                });
13490
13491
            // exit
13492
            lines.exit().remove();
13493
        }
13494
        else {
13495
            gridLineG.selectAll('line').remove();
13496
        }
13497
    };
13498
13499
    _chart._yAxisX = function () {
13500
        return _chart.useRightYAxis() ? _chart.width() - _chart.margins().right : _chart.margins().left;
13501
    };
13502
13503
    /**
13504
    #### .yAxisLabel([labelText, [, padding]])
13505
    Set or get the y axis label. If setting the label, you may optionally include additional padding
13506
    to the margin to make room for the label. By default the padded is set to 12 to accomodate the
13507
    text height.
13508
    **/
13509
    _chart.yAxisLabel = function (_, padding) {
13510
        if (!arguments.length) {
13511
            return _yAxisLabel;
13512
        }
13513
        _yAxisLabel = _;
13514
        _chart.margins().left -= _yAxisLabelPadding;
13515
        _yAxisLabelPadding = (padding === undefined) ? DEFAULT_AXIS_LABEL_PADDING : padding;
13516
        _chart.margins().left += _yAxisLabelPadding;
13517
        return _chart;
13518
    };
13519
13520
    /**
13521
    #### .y([yScale])
13522
    Get or set the y scale. The y scale is typically automatically determined by the chart implementation.
13523
13524
    **/
13525
    _chart.y = function (_) {
13526
        if (!arguments.length) {
13527
            return _y;
13528
        }
13529
        _y = _;
13530
        return _chart;
13531
    };
13532
13533
    /**
13534
    #### .yAxis([yAxis])
13535
    Set or get the y axis used by the coordinate grid chart instance. This function is most useful
13536
    when y axis customization is required. The y axis in dc.js is simply an instance of a [d3 axis
13537
    object](https://github.com/mbostock/d3/wiki/SVG-Axes#wiki-_axis); therefore it supports any
13538
    valid d3 axis manipulation. **Caution**: The y axis is usually generated internally by dc;
13539
    resetting it may cause unexpected results.
13540
    ```js
13541
    // customize y axis tick format
13542
    chart.yAxis().tickFormat(function(v) {return v + '%';});
13543
    // customize y axis tick values
13544
    chart.yAxis().tickValues([0, 100, 200, 300]);
13545
    ```
13546
13547
    **/
13548
    _chart.yAxis = function (y) {
13549
        if (!arguments.length) {
13550
            return _yAxis;
13551
        }
13552
        _yAxis = y;
13553
        return _chart;
13554
    };
13555
13556
    /**
13557
    #### .elasticY([boolean])
13558
    Turn on/off elastic y axis behavior. If y axis elasticity is turned on, then the grid chart will
13559
    attempt to recalculate the y axis range whenever a redraw event is triggered.
13560
13561
    **/
13562
    _chart.elasticY = function (_) {
13563
        if (!arguments.length) {
13564
            return _yElasticity;
13565
        }
13566
        _yElasticity = _;
13567
        return _chart;
13568
    };
13569
13570
    /**
13571
    #### .renderHorizontalGridLines([boolean])
13572
    Turn on/off horizontal grid lines.
13573
13574
    **/
13575
    _chart.renderHorizontalGridLines = function (_) {
13576
        if (!arguments.length) {
13577
            return _renderHorizontalGridLine;
13578
        }
13579
        _renderHorizontalGridLine = _;
13580
        return _chart;
13581
    };
13582
13583
    /**
13584
    #### .renderVerticalGridLines([boolean])
13585
    Turn on/off vertical grid lines.
13586
13587
    **/
13588
    _chart.renderVerticalGridLines = function (_) {
13589
        if (!arguments.length) {
13590
            return _renderVerticalGridLine;
13591
        }
13592
        _renderVerticalGridLine = _;
13593
        return _chart;
13594
    };
13595
13596
    /**
13597
    #### .xAxisMin()
13598
    Calculates the minimum x value to display in the chart. Includes xAxisPadding if set.
13599
    **/
13600
    _chart.xAxisMin = function () {
13601
        var min = d3.min(_chart.data(), function (e) {
13602
            return _chart.keyAccessor()(e);
13603
        });
13604
        return dc.utils.subtract(min, _xAxisPadding);
13605
    };
13606
13607
    /**
13608
    #### .xAxisMax()
13609
    Calculates the maximum x value to display in the chart. Includes xAxisPadding if set.
13610
    **/
13611
    _chart.xAxisMax = function () {
13612
        var max = d3.max(_chart.data(), function (e) {
13613
            return _chart.keyAccessor()(e);
13614
        });
13615
        return dc.utils.add(max, _xAxisPadding);
13616
    };
13617
13618
    /**
13619
    #### .yAxisMin()
13620
    Calculates the minimum y value to display in the chart. Includes yAxisPadding if set.
13621
    **/
13622
    _chart.yAxisMin = function () {
13623
        var min = d3.min(_chart.data(), function (e) {
13624
            return _chart.valueAccessor()(e);
13625
        });
13626
        return dc.utils.subtract(min, _yAxisPadding);
13627
    };
13628
13629
    /**
13630
    #### .yAxisMax()
13631
    Calculates the maximum y value to display in the chart. Includes yAxisPadding if set.
13632
    **/
13633
    _chart.yAxisMax = function () {
13634
        var max = d3.max(_chart.data(), function (e) {
13635
            return _chart.valueAccessor()(e);
13636
        });
13637
        return dc.utils.add(max, _yAxisPadding);
13638
    };
13639
13640
    /**
13641
    #### .yAxisPadding([padding])
13642
    Set or get y axis padding for the elastic y axis. The padding will be added to the top of the y
13643
    axis if elasticY is turned on; otherwise it is ignored.
13644
13645
    * padding can be an integer or percentage in string (e.g. '10%'). Padding can be applied to
13646
    number or date axes. When padding a date axis, an integer represents number of days being padded
13647
    and a percentage string will be treated the same as an integer.
13648
13649
    **/
13650
    _chart.yAxisPadding = function (_) {
13651
        if (!arguments.length) {
13652
            return _yAxisPadding;
13653
        }
13654
        _yAxisPadding = _;
13655
        return _chart;
13656
    };
13657
13658
    _chart.yAxisHeight = function () {
13659
        return _chart.effectiveHeight();
13660
    };
13661
13662
    /**
13663
    #### .round([rounding function])
13664
    Set or get the rounding function used to quantize the selection when brushing is enabled.
13665
    ```js
13666
    // set x unit round to by month, this will make sure range selection brush will
13667
    // select whole months
13668
    chart.round(d3.time.month.round);
13669
    ```
13670
13671
    **/
13672
    _chart.round = function (_) {
13673
        if (!arguments.length) {
13674
            return _round;
13675
        }
13676
        _round = _;
13677
        return _chart;
13678
    };
13679
13680
    _chart._rangeBandPadding = function (_) {
13681
        if (!arguments.length) {
13682
            return _rangeBandPadding;
13683
        }
13684
        _rangeBandPadding = _;
13685
        return _chart;
13686
    };
13687
13688
    _chart._outerRangeBandPadding = function (_) {
13689
        if (!arguments.length) {
13690
            return _outerRangeBandPadding;
13691
        }
13692
        _outerRangeBandPadding = _;
13693
        return _chart;
13694
    };
13695
13696
    dc.override(_chart, 'filter', function (_) {
13697
        if (!arguments.length) {
13698
            return _chart._filter();
13699
        }
13700
13701
        _chart._filter(_);
13702
13703
        if (_) {
13704
            _chart.brush().extent(_);
13705
        } else {
13706
            _chart.brush().clear();
13707
        }
13708
13709
        return _chart;
13710
    });
13711
13712
    _chart.brush = function (_) {
13713
        if (!arguments.length) {
13714
            return _brush;
13715
        }
13716
        _brush = _;
13717
        return _chart;
13718
    };
13719
13720
    function brushHeight() {
13721
        return _chart._xAxisY() - _chart.margins().top;
13722
    }
13723
13724
    _chart.renderBrush = function (g) {
13725
        if (_brushOn) {
13726
            _brush.on('brush', _chart._brushing);
13727
            _brush.on('brushstart', _chart._disableMouseZoom);
13728
            _brush.on('brushend', configureMouseZoom);
13729
13730
            var gBrush = g.append('g')
13731
                .attr('class', 'brush')
13732
                .attr('transform', 'translate(' + _chart.margins().left + ',' + _chart.margins().top + ')')
13733
                .call(_brush.x(_chart.x()));
13734
            _chart.setBrushY(gBrush);
13735
            _chart.setHandlePaths(gBrush);
13736
13737
            if (_chart.hasFilter()) {
13738
                _chart.redrawBrush(g);
13739
            }
13740
        }
13741
    };
13742
13743
    _chart.setHandlePaths = function (gBrush) {
13744
        gBrush.selectAll('.resize').append('path').attr('d', _chart.resizeHandlePath);
13745
    };
13746
13747
    _chart.setBrushY = function (gBrush) {
13748
        gBrush.selectAll('rect').attr('height', brushHeight());
13749
    };
13750
13751
    _chart.extendBrush = function () {
13752
        var extent = _brush.extent();
13753
        if (_chart.round()) {
13754
            extent[0] = extent.map(_chart.round())[0];
13755
            extent[1] = extent.map(_chart.round())[1];
13756
13757
            _g.select('.brush')
13758
                .call(_brush.extent(extent));
13759
        }
13760
        return extent;
13761
    };
13762
13763
    _chart.brushIsEmpty = function (extent) {
13764
        return _brush.empty() || !extent || extent[1] <= extent[0];
13765
    };
13766
13767
    _chart._brushing = function () {
13768
        var extent = _chart.extendBrush();
13769
13770
        _chart.redrawBrush(_g);
13771
13772
        if (_chart.brushIsEmpty(extent)) {
13773
            dc.events.trigger(function () {
13774
                _chart.filter(null);
13775
                _chart.redrawGroup();
13776
            }, dc.constants.EVENT_DELAY);
13777
        } else {
13778
            var rangedFilter = dc.filters.RangedFilter(extent[0], extent[1]);
13779
13780
            dc.events.trigger(function () {
13781
                _chart.replaceFilter(rangedFilter);
13782
                _chart.redrawGroup();
13783
            }, dc.constants.EVENT_DELAY);
13784
        }
13785
    };
13786
13787
    _chart.redrawBrush = function (g) {
13788
        if (_brushOn) {
13789
            if (_chart.filter() && _chart.brush().empty()) {
13790
                _chart.brush().extent(_chart.filter());
13791
            }
13792
13793
            var gBrush = g.select('g.brush');
13794
            gBrush.call(_chart.brush().x(_chart.x()));
13795
            _chart.setBrushY(gBrush);
13796
        }
13797
13798
        _chart.fadeDeselectedArea();
13799
    };
13800
13801
    _chart.fadeDeselectedArea = function () {
13802
        // do nothing, sub-chart should override this function
13803
    };
13804
13805
    // borrowed from Crossfilter example
13806
    _chart.resizeHandlePath = function (d) {
13807
        var e = +(d === 'e'), x = e ? 1 : -1, y = brushHeight() / 3;
13808
        return 'M' + (0.5 * x) + ',' + y +
13809
            'A6,6 0 0 ' + e + ' ' + (6.5 * x) + ',' + (y + 6) +
13810
            'V' + (2 * y - 6) +
13811
            'A6,6 0 0 ' + e + ' ' + (0.5 * x) + ',' + (2 * y) +
13812
            'Z' +
13813
            'M' + (2.5 * x) + ',' + (y + 8) +
13814
            'V' + (2 * y - 8) +
13815
            'M' + (4.5 * x) + ',' + (y + 8) +
13816
            'V' + (2 * y - 8);
13817
    };
13818
13819
    function getClipPathId() {
13820
        return _chart.anchorName().replace(/[ .#]/g, '-') + '-clip';
13821
    }
13822
13823
    /**
13824
    #### .clipPadding([padding])
13825
    Get or set the padding in pixels for the clip path. Once set padding will be applied evenly to
13826
    the top, left, right, and bottom when the clip path is generated. If set to zero, the clip area
13827
    will be exactly the chart body area minus the margins.  Default: 5
13828
13829
    **/
13830
    _chart.clipPadding = function (p) {
13831
        if (!arguments.length) {
13832
            return _clipPadding;
13833
        }
13834
        _clipPadding = p;
13835
        return _chart;
13836
    };
13837
13838
    function generateClipPath() {
13839
        var defs = dc.utils.appendOrSelect(_parent, 'defs');
13840
        // cannot select <clippath> elements; bug in WebKit, must select by id
13841
        // https://groups.google.com/forum/#!topic/d3-js/6EpAzQ2gU9I
13842
        var id = getClipPathId();
13843
        var chartBodyClip = dc.utils.appendOrSelect(defs, '#' + id, 'clipPath').attr('id', id);
13844
13845
        var padding = _clipPadding * 2;
13846
13847
        dc.utils.appendOrSelect(chartBodyClip, 'rect')
13848
            .attr('width', _chart.xAxisLength() + padding)
13849
            .attr('height', _chart.yAxisHeight() + padding)
13850
            .attr('transform', 'translate(-' + _clipPadding + ', -' + _clipPadding + ')');
13851
    }
13852
13853
    _chart._preprocessData = function () {};
13854
13855
    _chart._doRender = function () {
13856
        _chart.resetSvg();
13857
13858
        _chart._preprocessData();
13859
13860
        _chart._generateG();
13861
        generateClipPath();
13862
13863
        drawChart(true);
13864
13865
        configureMouseZoom();
13866
13867
        return _chart;
13868
    };
13869
13870
    _chart._doRedraw = function () {
13871
        _chart._preprocessData();
13872
13873
        drawChart(false);
13874
        generateClipPath();
13875
13876
        return _chart;
13877
    };
13878
13879
    function drawChart (render) {
13880
        if (_chart.isOrdinal()) {
13881
            _brushOn = false;
13882
        }
13883
13884
        prepareXAxis(_chart.g());
13885
        _chart._prepareYAxis(_chart.g());
13886
13887
        _chart.plotData();
13888
13889
        if (_chart.elasticX() || _refocused || render) {
13890
            _chart.renderXAxis(_chart.g());
13891
        }
13892
13893
        if (_chart.elasticY() || render) {
13894
            _chart.renderYAxis(_chart.g());
13895
        }
13896
13897
        if (render) {
13898
            _chart.renderBrush(_chart.g());
13899
        } else {
13900
            _chart.redrawBrush(_chart.g());
13901
        }
13902
    }
13903
13904
    function configureMouseZoom () {
13905
        if (_mouseZoomable) {
13906
            _chart._enableMouseZoom();
13907
        }
13908
        else if (_hasBeenMouseZoomable) {
13909
            _chart._disableMouseZoom();
13910
        }
13911
    }
13912
13913
    _chart._enableMouseZoom = function () {
13914
        _hasBeenMouseZoomable = true;
13915
        _zoom.x(_chart.x())
13916
            .scaleExtent(_zoomScale)
13917
            .size([_chart.width(), _chart.height()])
13918
            .duration(_chart.transitionDuration());
13919
        _chart.root().call(_zoom);
13920
    };
13921
13922
    _chart._disableMouseZoom = function () {
13923
        _chart.root().call(_nullZoom);
13924
    };
13925
13926
    function constrainRange(range, constraint) {
13927
        var constrainedRange = [];
13928
        constrainedRange[0] = d3.max([range[0], constraint[0]]);
13929
        constrainedRange[1] = d3.min([range[1], constraint[1]]);
13930
        return constrainedRange;
13931
    }
13932
13933
    /**
13934
    #### .focus([range])
13935
    Zoom this chart to focus on the given range. The given range should be an array containing only
13936
    2 elements (`[start, end]`) defining a range in the x domain. If the range is not given or set
13937
    to null, then the zoom will be reset. _For focus to work elasticX has to be turned off;
13938
    otherwise focus will be ignored._
13939
    ```js
13940
    chart.on('renderlet', function(chart) {
13941
        // smooth the rendering through event throttling
13942
        dc.events.trigger(function(){
13943
            // focus some other chart to the range selected by user on this chart
13944
            someOtherChart.focus(chart.filter());
13945
        });
13946
    })
13947
    ```
13948
13949
    **/
13950
    _chart.focus = function (range) {
13951
        if (hasRangeSelected(range)) {
13952
            _chart.x().domain(range);
13953
        } else {
13954
            _chart.x().domain(_xOriginalDomain);
13955
        }
13956
13957
        _zoom.x(_chart.x());
13958
        zoomHandler();
13959
    };
13960
13961
    _chart.refocused = function () {
13962
        return _refocused;
13963
    };
13964
13965
    _chart.focusChart = function (c) {
13966
        if (!arguments.length) {
13967
            return _focusChart;
13968
        }
13969
        _focusChart = c;
13970
        _chart.on('filtered', function (chart) {
13971
            if (!chart.filter()) {
13972
                dc.events.trigger(function () {
13973
                    _focusChart.x().domain(_focusChart.xOriginalDomain());
13974
                });
13975
            } else if (!rangesEqual(chart.filter(), _focusChart.filter())) {
13976
                dc.events.trigger(function () {
13977
                    _focusChart.focus(chart.filter());
13978
                });
13979
            }
13980
        });
13981
        return _chart;
13982
    };
13983
13984
    function rangesEqual(range1, range2) {
13985
        if (!range1 && !range2) {
13986
            return true;
13987
        }
13988
        else if (!range1 || !range2) {
13989
            return false;
13990
        }
13991
        else if (range1.length === 0 && range2.length === 0) {
13992
            return true;
13993
        }
13994
        else if (range1[0].valueOf() === range2[0].valueOf() &&
13995
            range1[1].valueOf() === range2[1].valueOf()) {
13996
            return true;
13997
        }
13998
        return false;
13999
    }
14000
14001
    /**
14002
    #### .brushOn([boolean])
14003
    Turn on/off the brush-based range filter. When brushing is on then user can drag the mouse
14004
    across a chart with a quantitative scale to perform range filtering based on the extent of the
14005
    brush, or click on the bars of an ordinal bar chart or slices of a pie chart to filter and
14006
    unfilter them. However turning on the brush filter will disable other interactive elements on
14007
    the chart such as highlighting, tool tips, and reference lines. Zooming will still be possible
14008
    if enabled, but only via scrolling (panning will be disabled.) Default: true
14009
14010
    **/
14011
    _chart.brushOn = function (_) {
14012
        if (!arguments.length) {
14013
            return _brushOn;
14014
        }
14015
        _brushOn = _;
14016
        return _chart;
14017
    };
14018
14019
    function hasRangeSelected(range) {
14020
        return range instanceof Array && range.length > 1;
14021
    }
14022
14023
    return _chart;
14024
};
14025
14026
/**
14027
## Stack Mixin
14028
Stack Mixin is an mixin that provides cross-chart support of stackability using d3.layout.stack.
14029
14030
**/
14031
dc.stackMixin = function (_chart) {
14032
14033
    function prepareValues (layer, layerIdx) {
14034
        var valAccessor = layer.accessor || _chart.valueAccessor();
14035
        layer.name = String(layer.name || layerIdx);
14036
        layer.values = layer.group.all().map(function (d, i) {
14037
            return {
14038
                x: _chart.keyAccessor()(d, i),
14039
                y: layer.hidden ? null : valAccessor(d, i),
14040
                data: d,
14041
                layer: layer.name,
14042
                hidden: layer.hidden
14043
            };
14044
        });
14045
14046
        layer.values = layer.values.filter(domainFilter());
14047
        return layer.values;
14048
    }
14049
14050
    var _stackLayout = d3.layout.stack()
14051
        .values(prepareValues);
14052
14053
    var _stack = [];
14054
    var _titles = {};
14055
14056
    var _hidableStacks = false;
14057
14058
    function domainFilter() {
14059
        if (!_chart.x()) {
14060
            return d3.functor(true);
14061
        }
14062
        var xDomain = _chart.x().domain();
14063
        if (_chart.isOrdinal()) {
14064
            // TODO #416
14065
            //var domainSet = d3.set(xDomain);
14066
            return function () {
14067
                return true; //domainSet.has(p.x);
14068
            };
14069
        }
14070
        if (_chart.elasticX()) {
14071
            return function () { return true; };
14072
        }
14073
        return function (p) {
14074
            //return true;
14075
            return p.x >= xDomain[0] && p.x <= xDomain[xDomain.length - 1];
14076
        };
14077
    }
14078
14079
    /**
14080
    #### .stack(group[, name, accessor])
14081
    Stack a new crossfilter group onto this chart with an optional custom value accessor. All stacks
14082
    in the same chart will share the same key accessor and therefore the same set of keys.
14083
14084
    For example, in a stacked bar chart, the bars of each stack will be positioned using the same set
14085
    of keys on the x axis, while stacked vertically. If name is specified then it will be used to
14086
    generate the legend label.
14087
    ```js
14088
    // stack group using default accessor
14089
    chart.stack(valueSumGroup)
14090
    // stack group using custom accessor
14091
    .stack(avgByDayGroup, function(d){return d.value.avgByDay;});
14092
    ```
14093
14094
    **/
14095
    _chart.stack = function (group, name, accessor) {
14096
        if (!arguments.length) {
14097
            return _stack;
14098
        }
14099
14100
        if (arguments.length <= 2) {
14101
            accessor = name;
14102
        }
14103
14104
        var layer = {group:group};
14105
        if (typeof name === 'string') {
14106
            layer.name = name;
14107
        }
14108
        if (typeof accessor === 'function') {
14109
            layer.accessor = accessor;
14110
        }
14111
        _stack.push(layer);
14112
14113
        return _chart;
14114
    };
14115
14116
    dc.override(_chart, 'group', function (g, n, f) {
14117
        if (!arguments.length) {
14118
            return _chart._group();
14119
        }
14120
        _stack = [];
14121
        _titles = {};
14122
        _chart.stack(g, n);
14123
        if (f) {
14124
            _chart.valueAccessor(f);
14125
        }
14126
        return _chart._group(g, n);
14127
    });
14128
14129
    /**
14130
    #### .hidableStacks([boolean])
14131
    Allow named stacks to be hidden or shown by clicking on legend items.
14132
    This does not affect the behavior of hideStack or showStack.
14133
14134
    **/
14135
    _chart.hidableStacks = function (_) {
14136
        if (!arguments.length) {
14137
            return _hidableStacks;
14138
        }
14139
        _hidableStacks = _;
14140
        return _chart;
14141
    };
14142
14143
    function findLayerByName(n) {
14144
        var i = _stack.map(dc.pluck('name')).indexOf(n);
14145
        return _stack[i];
14146
    }
14147
14148
    /**
14149
    #### .hideStack(name)
14150
    Hide all stacks on the chart with the given name.
14151
    The chart must be re-rendered for this change to appear.
14152
14153
    **/
14154
    _chart.hideStack = function (stackName) {
14155
        var layer = findLayerByName(stackName);
14156
        if (layer) {
14157
            layer.hidden = true;
14158
        }
14159
        return _chart;
14160
    };
14161
14162
    /**
14163
    #### .showStack(name)
14164
    Show all stacks on the chart with the given name.
14165
    The chart must be re-rendered for this change to appear.
14166
14167
    **/
14168
    _chart.showStack = function (stackName) {
14169
        var layer = findLayerByName(stackName);
14170
        if (layer) {
14171
            layer.hidden = false;
14172
        }
14173
        return _chart;
14174
    };
14175
14176
    _chart.getValueAccessorByIndex = function (index) {
14177
        return _stack[index].accessor || _chart.valueAccessor();
14178
    };
14179
14180
    _chart.yAxisMin = function () {
14181
        var min = d3.min(flattenStack(), function (p) {
14182
            return (p.y + p.y0 < p.y0) ? (p.y + p.y0) : p.y0;
14183
        });
14184
14185
        return dc.utils.subtract(min, _chart.yAxisPadding());
14186
14187
    };
14188
14189
    _chart.yAxisMax = function () {
14190
        var max = d3.max(flattenStack(), function (p) {
14191
            return p.y + p.y0;
14192
        });
14193
14194
        return dc.utils.add(max, _chart.yAxisPadding());
14195
    };
14196
14197
    function flattenStack() {
14198
        var valueses = _chart.data().map(function (layer) { return layer.values; });
14199
        return Array.prototype.concat.apply([], valueses);
14200
    }
14201
14202
    _chart.xAxisMin = function () {
14203
        var min = d3.min(flattenStack(), dc.pluck('x'));
14204
        return dc.utils.subtract(min, _chart.xAxisPadding());
14205
    };
14206
14207
    _chart.xAxisMax = function () {
14208
        var max = d3.max(flattenStack(), dc.pluck('x'));
14209
        return dc.utils.add(max, _chart.xAxisPadding());
14210
    };
14211
14212
    /**
14213
    #### .title([stackName], [titleFunction])
14214
    Set or get the title function. Chart class will use this function to render svg title (usually interpreted by
14215
    browser as tooltips) for each child element in the chart, i.e. a slice in a pie chart or a bubble in a bubble chart.
14216
    Almost every chart supports title function however in grid coordinate chart you need to turn off brush in order to
14217
    use title otherwise the brush layer will block tooltip trigger.
14218
14219
    If the first argument is a stack name, the title function will get or set the title for that stack. If stackName
14220
    is not provided, the first stack is implied.
14221
    ```js
14222
    // set a title function on 'first stack'
14223
    chart.title('first stack', function(d) { return d.key + ': ' + d.value; });
14224
    // get a title function from 'second stack'
14225
    var secondTitleFunction = chart.title('second stack');
14226
    );
14227
    ```
14228
    **/
14229
    dc.override(_chart, 'title', function (stackName, titleAccessor) {
14230
        if (!stackName) {
14231
            return _chart._title();
14232
        }
14233
14234
        if (typeof stackName === 'function') {
14235
            return _chart._title(stackName);
14236
        }
14237
        if (stackName === _chart._groupName && typeof titleAccessor === 'function') {
14238
            return _chart._title(titleAccessor);
14239
        }
14240
14241
        if (typeof titleAccessor !== 'function') {
14242
            return _titles[stackName] || _chart._title();
14243
        }
14244
14245
        _titles[stackName] = titleAccessor;
14246
14247
        return _chart;
14248
    });
14249
14250
    /**
14251
     #### .stackLayout([layout])
14252
     Gets or sets the stack layout algorithm, which computes a baseline for each stack and
14253
     propagates it to the next.  The default is
14254
     [d3.layout.stack](https://github.com/mbostock/d3/wiki/Stack-Layout#stack).
14255
     **/
14256
    _chart.stackLayout = function (stack) {
14257
        if (!arguments.length) {
14258
            return _stackLayout;
14259
        }
14260
        _stackLayout = stack;
14261
        return _chart;
14262
    };
14263
14264
    function visability(l) {
14265
        return !l.hidden;
14266
    }
14267
14268
    _chart.data(function () {
14269
        var layers = _stack.filter(visability);
14270
        return layers.length ? _chart.stackLayout()(layers) : [];
14271
    });
14272
14273
    _chart._ordinalXDomain = function () {
14274
        var flat = flattenStack().map(dc.pluck('data'));
14275
        var ordered = _chart._computeOrderedGroups(flat);
14276
        return ordered.map(_chart.keyAccessor());
14277
    };
14278
14279
    _chart.colorAccessor(function (d) {
14280
        var layer = this.layer || this.name || d.name || d.layer;
14281
        return layer;
14282
    });
14283
14284
    _chart.legendables = function () {
14285
        return _stack.map(function (layer, i) {
14286
            return {
14287
                chart:_chart,
14288
                name:layer.name,
14289
                hidden: layer.hidden || false,
14290
                color:_chart.getColor.call(layer, layer.values, i)
14291
            };
14292
        });
14293
    };
14294
14295
    _chart.isLegendableHidden = function (d) {
14296
        var layer = findLayerByName(d.name);
14297
        return layer ? layer.hidden : false;
14298
    };
14299
14300
    _chart.legendToggle = function (d) {
14301
        if (_hidableStacks) {
14302
            if (_chart.isLegendableHidden(d)) {
14303
                _chart.showStack(d.name);
14304
            } else {
14305
                _chart.hideStack(d.name);
14306
            }
14307
            //_chart.redraw();
14308
            _chart.renderGroup();
14309
        }
14310
    };
14311
14312
    return _chart;
14313
};
14314
14315
/**
14316
## Cap Mixin
14317
Cap is a mixin that groups small data elements below a _cap_ into an *others* grouping for both the
14318
Row and Pie Charts.
14319
14320
The top ordered elements in the group up to the cap amount will be kept in the chart, and the rest
14321
will be replaced with an *others* element, with value equal to the sum of the replaced values. The
14322
keys of the elements below the cap limit are recorded in order to filter by those keys when the
14323
*others* element is clicked.
14324
14325
**/
14326
dc.capMixin = function (_chart) {
14327
14328
    var _cap = Infinity;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Infinity as _cap. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
14329
14330
    var _othersLabel = 'Others';
14331
14332
    var _othersGrouper = function (topRows) {
14333
        var topRowsSum = d3.sum(topRows, _chart.valueAccessor()),
14334
            allRows = _chart.group().all(),
14335
            allRowsSum = d3.sum(allRows, _chart.valueAccessor()),
14336
            topKeys = topRows.map(_chart.keyAccessor()),
14337
            allKeys = allRows.map(_chart.keyAccessor()),
14338
            topSet = d3.set(topKeys),
14339
            others = allKeys.filter(function (d) {return !topSet.has(d);});
14340
        if (allRowsSum > topRowsSum) {
14341
            return topRows.concat([{'others': others, 'key': _othersLabel, 'value': allRowsSum - topRowsSum}]);
14342
        }
14343
        return topRows;
14344
    };
14345
14346
    _chart.cappedKeyAccessor = function (d, i) {
14347
        if (d.others) {
14348
            return d.key;
14349
        }
14350
        return _chart.keyAccessor()(d, i);
14351
    };
14352
14353
    _chart.cappedValueAccessor = function (d, i) {
14354
        if (d.others) {
14355
            return d.value;
14356
        }
14357
        return _chart.valueAccessor()(d, i);
14358
    };
14359
14360
    _chart.data(function (group) {
14361
        if (_cap === Infinity) {
14362
            return _chart._computeOrderedGroups(group.all());
14363
        } else {
14364
            var topRows = group.top(_cap); // ordered by crossfilter group order (default value)
14365
            topRows = _chart._computeOrderedGroups(topRows); // re-order using ordering (default key)
14366
            if (_othersGrouper) {
14367
                return _othersGrouper(topRows);
14368
            }
14369
            return topRows;
14370
        }
14371
    });
14372
14373
    /**
14374
    #### .cap([count])
14375
    Get or set the count of elements to that will be included in the cap.
14376
    **/
14377
    _chart.cap = function (_) {
14378
        if (!arguments.length) {
14379
            return _cap;
14380
        }
14381
        _cap = _;
14382
        return _chart;
14383
    };
14384
14385
    /**
14386
    #### .othersLabel([label])
14387
    Get or set the label for *Others* slice when slices cap is specified. Default label is **Others**.
14388
    **/
14389
    _chart.othersLabel = function (_) {
14390
        if (!arguments.length) {
14391
            return _othersLabel;
14392
        }
14393
        _othersLabel = _;
14394
        return _chart;
14395
    };
14396
14397
    /**
14398
    #### .othersGrouper([grouperFunction])
14399
    Get or set the grouper function that will perform the insertion of data for the *Others* slice
14400
    if the slices cap is specified. If set to a falsy value, no others will be added. By default the
14401
    grouper function computes the sum of all values below the cap.
14402
    ```js
14403
    chart.othersGrouper(function (data) {
14404
        // compute the value for others, presumably the sum of all values below the cap
14405
        var othersSum  = yourComputeOthersValueLogic(data)
14406
14407
        // the keys are needed to properly filter when the others element is clicked
14408
        var othersKeys = yourComputeOthersKeysArrayLogic(data);
14409
14410
        // add the others row to the dataset
14411
        data.push({'key': 'Others', 'value': othersSum, 'others': othersKeys });
14412
14413
        return data;
14414
    });
14415
    ```
14416
    **/
14417
    _chart.othersGrouper = function (_) {
14418
        if (!arguments.length) {
14419
            return _othersGrouper;
14420
        }
14421
        _othersGrouper = _;
14422
        return _chart;
14423
    };
14424
14425
    dc.override(_chart, 'onClick', function (d) {
14426
        if (d.others) {
14427
            _chart.filter([d.others]);
14428
        }
14429
        _chart._onClick(d);
14430
    });
14431
14432
    return _chart;
14433
};
14434
14435
/**
14436
## Bubble Mixin
14437
Includes: [Color Mixin](#color-mixin)
14438
14439
This Mixin provides reusable functionalities for any chart that needs to visualize data using bubbles.
14440
14441
**/
14442
dc.bubbleMixin = function (_chart) {
14443
    var _maxBubbleRelativeSize = 0.3;
14444
    var _minRadiusWithLabel = 10;
14445
14446
    _chart.BUBBLE_NODE_CLASS = 'node';
14447
    _chart.BUBBLE_CLASS = 'bubble';
14448
    _chart.MIN_RADIUS = 10;
14449
14450
    _chart = dc.colorMixin(_chart);
14451
14452
    _chart.renderLabel(true);
14453
14454
    _chart.data(function (group) {
14455
        return group.top(Infinity);
14456
    });
14457
14458
    var _r = d3.scale.linear().domain([0, 100]);
14459
14460
    var _rValueAccessor = function (d) {
14461
        return d.r;
14462
    };
14463
14464
    /**
14465
    #### .r([bubbleRadiusScale])
14466
    Get or set the bubble radius scale. By default the bubble chart uses
14467
    `d3.scale.linear().domain([0, 100])` as its r scale .
14468
14469
    **/
14470
    _chart.r = function (_) {
14471
        if (!arguments.length) {
14472
            return _r;
14473
        }
14474
        _r = _;
14475
        return _chart;
14476
    };
14477
14478
    /**
14479
    #### .radiusValueAccessor([radiusValueAccessor])
14480
    Get or set the radius value accessor function. If set, the radius value accessor function will
14481
    be used to retrieve a data value for each bubble. The data retrieved then will be mapped using
14482
    the r scale to the actual bubble radius. This allows you to encode a data dimension using bubble
14483
    size.
14484
14485
    **/
14486
    _chart.radiusValueAccessor = function (_) {
14487
        if (!arguments.length) {
14488
            return _rValueAccessor;
14489
        }
14490
        _rValueAccessor = _;
14491
        return _chart;
14492
    };
14493
14494
    _chart.rMin = function () {
14495
        var min = d3.min(_chart.data(), function (e) {
14496
            return _chart.radiusValueAccessor()(e);
14497
        });
14498
        return min;
14499
    };
14500
14501
    _chart.rMax = function () {
14502
        var max = d3.max(_chart.data(), function (e) {
14503
            return _chart.radiusValueAccessor()(e);
14504
        });
14505
        return max;
14506
    };
14507
14508
    _chart.bubbleR = function (d) {
14509
        var value = _chart.radiusValueAccessor()(d);
14510
        var r = _chart.r()(value);
14511
        if (isNaN(r) || value <= 0) {
14512
            r = 0;
14513
        }
14514
        return r;
14515
    };
14516
14517
    var labelFunction = function (d) {
14518
        return _chart.label()(d);
14519
    };
14520
14521
    var labelOpacity = function (d) {
14522
        return (_chart.bubbleR(d) > _minRadiusWithLabel) ? 1 : 0;
14523
    };
14524
14525
    _chart._doRenderLabel = function (bubbleGEnter) {
14526
        if (_chart.renderLabel()) {
14527
            var label = bubbleGEnter.select('text');
14528
14529
            if (label.empty()) {
14530
                label = bubbleGEnter.append('text')
14531
                    .attr('text-anchor', 'middle')
14532
                    .attr('dy', '.3em')
14533
                    .on('click', _chart.onClick);
14534
            }
14535
14536
            label
14537
                .attr('opacity', 0)
14538
                .text(labelFunction);
14539
            dc.transition(label, _chart.transitionDuration())
14540
                .attr('opacity', labelOpacity);
14541
        }
14542
    };
14543
14544
    _chart.doUpdateLabels = function (bubbleGEnter) {
14545
        if (_chart.renderLabel()) {
14546
            var labels = bubbleGEnter.selectAll('text')
14547
                .text(labelFunction);
14548
            dc.transition(labels, _chart.transitionDuration())
14549
                .attr('opacity', labelOpacity);
14550
        }
14551
    };
14552
14553
    var titleFunction = function (d) {
14554
        return _chart.title()(d);
14555
    };
14556
14557
    _chart._doRenderTitles = function (g) {
14558
        if (_chart.renderTitle()) {
14559
            var title = g.select('title');
14560
14561
            if (title.empty()) {
14562
                g.append('title').text(titleFunction);
14563
            }
14564
        }
14565
    };
14566
14567
    _chart.doUpdateTitles = function (g) {
14568
        if (_chart.renderTitle()) {
14569
            g.selectAll('title').text(titleFunction);
14570
        }
14571
    };
14572
14573
    /**
14574
    #### .minRadiusWithLabel([radius])
14575
    Get or set the minimum radius for label rendering. If a bubble's radius is less than this value
14576
    then no label will be rendered.  Default: 10
14577
14578
    **/
14579
    _chart.minRadiusWithLabel = function (_) {
14580
        if (!arguments.length) {
14581
            return _minRadiusWithLabel;
14582
        }
14583
        _minRadiusWithLabel = _;
14584
        return _chart;
14585
    };
14586
14587
    /**
14588
    #### .maxBubbleRelativeSize([relativeSize])
14589
    Get or set the maximum relative size of a bubble to the length of x axis. This value is useful
14590
    when the difference in radius between bubbles is too great. Default: 0.3
14591
14592
    **/
14593
    _chart.maxBubbleRelativeSize = function (_) {
14594
        if (!arguments.length) {
14595
            return _maxBubbleRelativeSize;
14596
        }
14597
        _maxBubbleRelativeSize = _;
14598
        return _chart;
14599
    };
14600
14601
    _chart.fadeDeselectedArea = function () {
14602
        if (_chart.hasFilter()) {
14603
            _chart.selectAll('g.' + _chart.BUBBLE_NODE_CLASS).each(function (d) {
14604
                if (_chart.isSelectedNode(d)) {
14605
                    _chart.highlightSelected(this);
14606
                } else {
14607
                    _chart.fadeDeselected(this);
14608
                }
14609
            });
14610
        } else {
14611
            _chart.selectAll('g.' + _chart.BUBBLE_NODE_CLASS).each(function () {
14612
                _chart.resetHighlight(this);
14613
            });
14614
        }
14615
    };
14616
14617
    _chart.isSelectedNode = function (d) {
14618
        return _chart.hasFilter(d.key);
14619
    };
14620
14621
    _chart.onClick = function (d) {
14622
        var filter = d.key;
14623
        dc.events.trigger(function () {
14624
            _chart.filter(filter);
14625
            _chart.redrawGroup();
14626
        });
14627
    };
14628
14629
    return _chart;
14630
};
14631
14632
/**
14633
## Pie Chart
14634
Includes: [Cap Mixin](#cap-mixin), [Color Mixin](#color-mixin), [Base Mixin](#base-mixin)
14635
14636
The pie chart implementation is usually used to visualize a small categorical distribution.  The pie
14637
chart uses keyAccessor to determine the slices, and valueAccessor to calculate the size of each
14638
slice relative to the sum of all values. Slices are ordered by `.ordering` which defaults to sorting
14639
by key.
14640
14641
Examples:
14642
14643
* [Nasdaq 100 Index](http://dc-js.github.com/dc.js/)
14644
#### dc.pieChart(parent[, chartGroup])
14645
Create a pie chart instance and attaches it to the given parent element.
14646
14647
Parameters:
14648
14649
* parent : string | node | selection - any valid
14650
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
14651
 a dom block element such as a div; or a dom element or d3 selection.
14652
14653
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
14654
 Interaction with a chart will only trigger events and redraws within the chart's group.
14655
14656
Returns:
14657
A newly created pie chart instance
14658
14659
```js
14660
// create a pie chart under #chart-container1 element using the default global chart group
14661
var chart1 = dc.pieChart('#chart-container1');
14662
// create a pie chart under #chart-container2 element using chart group A
14663
var chart2 = dc.pieChart('#chart-container2', 'chartGroupA');
14664
```
14665
14666
**/
14667
dc.pieChart = function (parent, chartGroup) {
14668
    var DEFAULT_MIN_ANGLE_FOR_LABEL = 0.5;
14669
14670
    var _sliceCssClass = 'pie-slice';
14671
    var _emptyCssClass = 'empty-chart';
14672
    var _emptyTitle = 'empty';
14673
14674
    var _radius,
14675
        _innerRadius = 0;
14676
14677
    var _g;
14678
    var _cx;
14679
    var _cy;
14680
    var _minAngleForLabel = DEFAULT_MIN_ANGLE_FOR_LABEL;
14681
    var _externalLabelRadius;
14682
    var _chart = dc.capMixin(dc.colorMixin(dc.baseMixin({})));
14683
14684
    _chart.colorAccessor(_chart.cappedKeyAccessor);
14685
14686
    _chart.title(function (d) {
14687
        return _chart.cappedKeyAccessor(d) + ': ' + _chart.cappedValueAccessor(d);
14688
    });
14689
14690
    /**
14691
    #### .slicesCap([cap])
14692
    Get or set the maximum number of slices the pie chart will generate. The top slices are determined by
14693
    value from high to low. Other slices exeeding the cap will be rolled up into one single *Others* slice.
14694
    The resulting data will still be sorted by .ordering (default by key).
14695
14696
    **/
14697
    _chart.slicesCap = _chart.cap;
14698
14699
    _chart.label(_chart.cappedKeyAccessor);
14700
    _chart.renderLabel(true);
14701
14702
    _chart.transitionDuration(350);
14703
14704
    _chart._doRender = function () {
14705
        _chart.resetSvg();
14706
14707
        _g = _chart.svg()
14708
            .append('g')
14709
            .attr('transform', 'translate(' + _chart.cx() + ',' + _chart.cy() + ')');
14710
14711
        drawChart();
14712
14713
        return _chart;
14714
    };
14715
14716
    function drawChart() {
14717
        // set radius on basis of chart dimension if missing
14718
        _radius = _radius ? _radius : d3.min([_chart.width(), _chart.height()]) / 2;
14719
14720
        var arc = buildArcs();
14721
14722
        var pie = pieLayout();
14723
        var pieData;
14724
        // if we have data...
14725
        if (d3.sum(_chart.data(), _chart.valueAccessor())) {
14726
            pieData = pie(_chart.data());
14727
            _g.classed(_emptyCssClass, false);
14728
        } else {
14729
            // otherwise we'd be getting NaNs, so override
14730
            // note: abuse others for its ignoring the value accessor
14731
            pieData = pie([{key:_emptyTitle, value:1, others: [_emptyTitle]}]);
14732
            _g.classed(_emptyCssClass, true);
14733
        }
14734
14735
        if (_g) {
14736
            var slices = _g.selectAll('g.' + _sliceCssClass)
14737
                .data(pieData);
14738
14739
            createElements(slices, arc, pieData);
14740
14741
            updateElements(pieData, arc);
14742
14743
            removeElements(slices);
14744
14745
            highlightFilter();
14746
        }
14747
    }
14748
14749
    function createElements(slices, arc, pieData) {
14750
        var slicesEnter = createSliceNodes(slices);
14751
14752
        createSlicePath(slicesEnter, arc);
14753
14754
        createTitles(slicesEnter);
14755
14756
        createLabels(pieData, arc);
14757
    }
14758
14759
    function createSliceNodes(slices) {
14760
        var slicesEnter = slices
14761
            .enter()
14762
            .append('g')
14763
            .attr('class', function (d, i) {
14764
                return _sliceCssClass + ' _' + i;
14765
            });
14766
        return slicesEnter;
14767
    }
14768
14769
    function createSlicePath(slicesEnter, arc) {
14770
        var slicePath = slicesEnter.append('path')
14771
            .attr('fill', fill)
14772
            .on('click', onClick)
14773
            .attr('d', function (d, i) {
14774
                return safeArc(d, i, arc);
14775
            });
14776
14777
        dc.transition(slicePath, _chart.transitionDuration(), function (s) {
14778
            s.attrTween('d', tweenPie);
14779
        });
14780
    }
14781
14782
    function createTitles(slicesEnter) {
14783
        if (_chart.renderTitle()) {
14784
            slicesEnter.append('title').text(function (d) {
14785
                return _chart.title()(d.data);
14786
            });
14787
        }
14788
    }
14789
14790
    function positionLabels(labelsEnter, arc) {
14791
        dc.transition(labelsEnter, _chart.transitionDuration())
14792
            .attr('transform', function (d) {
14793
                return labelPosition(d, arc);
14794
            })
14795
            .attr('text-anchor', 'middle')
14796
            .text(function (d) {
14797
                var data = d.data;
14798
                if ((sliceHasNoData(data) || sliceTooSmall(d)) && !isSelectedSlice(d)) {
14799
                    return '';
14800
                }
14801
                return _chart.label()(d.data);
14802
            });
14803
    }
14804
14805
    function createLabels(pieData, arc) {
14806
        if (_chart.renderLabel()) {
14807
            var labels = _g.selectAll('text.' + _sliceCssClass)
14808
                .data(pieData);
14809
14810
            labels.exit().remove();
14811
14812
            var labelsEnter = labels
14813
                .enter()
14814
                .append('text')
14815
                .attr('class', function (d, i) {
14816
                    var classes = _sliceCssClass + ' _' + i;
14817
                    if (_externalLabelRadius) {
14818
                        classes += ' external';
14819
                    }
14820
                    return classes;
14821
                })
14822
                .on('click', onClick);
14823
            positionLabels(labelsEnter, arc);
14824
        }
14825
    }
14826
14827
    function updateElements(pieData, arc) {
14828
        updateSlicePaths(pieData, arc);
14829
        updateLabels(pieData, arc);
14830
        updateTitles(pieData);
14831
    }
14832
14833
    function updateSlicePaths(pieData, arc) {
14834
        var slicePaths = _g.selectAll('g.' + _sliceCssClass)
14835
            .data(pieData)
14836
            .select('path')
14837
            .attr('d', function (d, i) {
14838
                return safeArc(d, i, arc);
14839
            });
14840
        dc.transition(slicePaths, _chart.transitionDuration(),
14841
            function (s) {
14842
                s.attrTween('d', tweenPie);
14843
            }).attr('fill', fill);
14844
    }
14845
14846
    function updateLabels(pieData, arc) {
14847
        if (_chart.renderLabel()) {
14848
            var labels = _g.selectAll('text.' + _sliceCssClass)
14849
                .data(pieData);
14850
            positionLabels(labels, arc);
14851
        }
14852
    }
14853
14854
    function updateTitles(pieData) {
14855
        if (_chart.renderTitle()) {
14856
            _g.selectAll('g.' + _sliceCssClass)
14857
                .data(pieData)
14858
                .select('title')
14859
                .text(function (d) {
14860
                    return _chart.title()(d.data);
14861
                });
14862
        }
14863
    }
14864
14865
    function removeElements(slices) {
14866
        slices.exit().remove();
14867
    }
14868
14869
    function highlightFilter() {
14870
        if (_chart.hasFilter()) {
14871
            _chart.selectAll('g.' + _sliceCssClass).each(function (d) {
14872
                if (isSelectedSlice(d)) {
14873
                    _chart.highlightSelected(this);
14874
                } else {
14875
                    _chart.fadeDeselected(this);
14876
                }
14877
            });
14878
        } else {
14879
            _chart.selectAll('g.' + _sliceCssClass).each(function () {
14880
                _chart.resetHighlight(this);
14881
            });
14882
        }
14883
    }
14884
14885
    /**
14886
    #### .innerRadius([innerRadius])
14887
    Get or set the inner radius of the pie chart. If the inner radius is greater than 0px then the
14888
    pie chart will be rendered as a doughnut chart. Default inner radius is 0px.
14889
14890
    **/
14891
    _chart.innerRadius = function (r) {
14892
        if (!arguments.length) {
14893
            return _innerRadius;
14894
        }
14895
        _innerRadius = r;
14896
        return _chart;
14897
    };
14898
14899
    /**
14900
    #### .radius([radius])
14901
    Get or set the outer radius. If the radius is not set, it will be half of the minimum of the
14902
    chart width and height.
14903
14904
    **/
14905
    _chart.radius = function (r) {
14906
        if (!arguments.length) {
14907
            return _radius;
14908
        }
14909
        _radius = r;
14910
        return _chart;
14911
    };
14912
14913
    /**
14914
    #### .cx([cx])
14915
    Get or set center x coordinate position. Default is center of svg.
14916
14917
    **/
14918
    _chart.cx = function (cx) {
14919
        if (!arguments.length) {
14920
            return (_cx ||  _chart.width() / 2);
14921
        }
14922
        _cx = cx;
14923
        return _chart;
14924
    };
14925
14926
    /**
14927
    #### .cy([cy])
14928
    Get or set center y coordinate position. Default is center of svg.
14929
14930
    **/
14931
    _chart.cy = function (cy) {
14932
        if (!arguments.length) {
14933
            return (_cy ||  _chart.height() / 2);
14934
        }
14935
        _cy = cy;
14936
        return _chart;
14937
    };
14938
14939
    function buildArcs() {
14940
        return d3.svg.arc().outerRadius(_radius).innerRadius(_innerRadius);
14941
    }
14942
14943
    function isSelectedSlice(d) {
14944
        return _chart.hasFilter(_chart.cappedKeyAccessor(d.data));
14945
    }
14946
14947
    _chart._doRedraw = function () {
14948
        drawChart();
14949
        return _chart;
14950
    };
14951
14952
    /**
14953
    #### .minAngleForLabel([minAngle])
14954
    Get or set the minimal slice angle for label rendering. Any slice with a smaller angle will not
14955
    display a slice label.  Default min angle is 0.5.
14956
    **/
14957
    _chart.minAngleForLabel = function (_) {
14958
        if (!arguments.length) {
14959
            return _minAngleForLabel;
14960
        }
14961
        _minAngleForLabel = _;
14962
        return _chart;
14963
    };
14964
14965
    function pieLayout() {
14966
        return d3.layout.pie().sort(null).value(_chart.cappedValueAccessor);
14967
    }
14968
14969
    function sliceTooSmall(d) {
14970
        var angle = (d.endAngle - d.startAngle);
14971
        return isNaN(angle) || angle < _minAngleForLabel;
14972
    }
14973
14974
    function sliceHasNoData(d) {
14975
        return _chart.cappedValueAccessor(d) === 0;
14976
    }
14977
14978
    function tweenPie(b) {
14979
        b.innerRadius = _innerRadius;
14980
        var current = this._current;
14981
        if (isOffCanvas(current)) {
14982
            current = {startAngle: 0, endAngle: 0};
14983
        }
14984
        var i = d3.interpolate(current, b);
14985
        this._current = i(0);
14986
        return function (t) {
14987
            return safeArc(i(t), 0, buildArcs());
14988
        };
14989
    }
14990
14991
    function isOffCanvas(current) {
14992
        return !current || isNaN(current.startAngle) || isNaN(current.endAngle);
14993
    }
14994
14995
    function fill(d, i) {
14996
        return _chart.getColor(d.data, i);
14997
    }
14998
14999
    function onClick(d, i) {
15000
        if (_g.attr('class') !== _emptyCssClass) {
15001
            _chart.onClick(d.data, i);
15002
        }
15003
    }
15004
15005
    function safeArc(d, i, arc) {
15006
        var path = arc(d, i);
15007
        if (path.indexOf('NaN') >= 0) {
15008
            path = 'M0,0';
15009
        }
15010
        return path;
15011
    }
15012
15013
    /**
15014
     #### .emptyTitle([title])
15015
     Title to use for the only slice when there is no data
15016
     */
15017
    _chart.emptyTitle = function (title) {
15018
        if (arguments.length === 0) {
15019
            return _emptyTitle;
15020
        }
15021
        _emptyTitle = title;
15022
        return _chart;
15023
    };
15024
15025
    /**
15026
     #### .externalLabels([radius])
15027
     Position slice labels offset from the outer edge of the chart
15028
15029
     The given argument sets the radial offset.
15030
     */
15031
    _chart.externalLabels = function (radius) {
15032
        if (arguments.length === 0) {
15033
            return _externalLabelRadius;
15034
        } else if (radius) {
15035
            _externalLabelRadius = radius;
15036
        } else {
15037
            _externalLabelRadius = undefined;
15038
        }
15039
15040
        return _chart;
15041
    };
15042
15043
    function labelPosition(d, arc) {
15044
        var centroid;
15045
        if (_externalLabelRadius) {
15046
            centroid = d3.svg.arc()
15047
                .outerRadius(_radius + _externalLabelRadius)
15048
                .innerRadius(_radius + _externalLabelRadius)
15049
                .centroid(d);
15050
        } else {
15051
            centroid = arc.centroid(d);
15052
        }
15053
        if (isNaN(centroid[0]) || isNaN(centroid[1])) {
15054
            return 'translate(0,0)';
15055
        } else {
15056
            return 'translate(' + centroid + ')';
15057
        }
15058
    }
15059
15060
    _chart.legendables = function () {
15061
        return _chart.data().map(function (d, i) {
15062
            var legendable = {name: d.key, data: d.value, others: d.others, chart:_chart};
15063
            legendable.color = _chart.getColor(d, i);
15064
            return legendable;
15065
        });
15066
    };
15067
15068
    _chart.legendHighlight = function (d) {
15069
        highlightSliceFromLegendable(d, true);
15070
    };
15071
15072
    _chart.legendReset = function (d) {
15073
        highlightSliceFromLegendable(d, false);
15074
    };
15075
15076
    _chart.legendToggle = function (d) {
15077
        _chart.onClick({key: d.name, others: d.others});
15078
    };
15079
15080
    function highlightSliceFromLegendable(legendable, highlighted) {
15081
        _chart.selectAll('g.pie-slice').each(function (d) {
15082
            if (legendable.name === d.data.key) {
15083
                d3.select(this).classed('highlight', highlighted);
15084
            }
15085
        });
15086
    }
15087
15088
    return _chart.anchor(parent, chartGroup);
15089
};
15090
15091
/**
15092
## Bar Chart
15093
Includes: [Stack Mixin](#stack Mixin), [Coordinate Grid Mixin](#coordinate-grid-mixin)
15094
15095
Concrete bar chart/histogram implementation.
15096
15097
Examples:
15098
15099
* [Nasdaq 100 Index](http://dc-js.github.com/dc.js/)
15100
* [Canadian City Crime Stats](http://dc-js.github.com/dc.js/crime/index.html)
15101
#### dc.barChart(parent[, chartGroup])
15102
Create a bar chart instance and attach it to the given parent element.
15103
15104
Parameters:
15105
* parent : string | node | selection | compositeChart - any valid
15106
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
15107
 a dom block element such as a div; or a dom element or d3 selection.
15108
 If the bar chart is a sub-chart in a [Composite Chart](#composite-chart) then pass in the parent composite
15109
 chart instance.
15110
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
15111
 Interaction with a chart will only trigger events and redraws within the chart's group.
15112
15113
Returns:
15114
A newly created bar chart instance
15115
15116
```js
15117
// create a bar chart under #chart-container1 element using the default global chart group
15118
var chart1 = dc.barChart('#chart-container1');
15119
// create a bar chart under #chart-container2 element using chart group A
15120
var chart2 = dc.barChart('#chart-container2', 'chartGroupA');
15121
// create a sub-chart under a composite parent chart
15122
var chart3 = dc.barChart(compositeChart);
15123
```
15124
15125
**/
15126
dc.barChart = function (parent, chartGroup) {
15127
    var MIN_BAR_WIDTH = 1;
15128
    var DEFAULT_GAP_BETWEEN_BARS = 2;
15129
15130
    var _chart = dc.stackMixin(dc.coordinateGridMixin({}));
15131
15132
    var _gap = DEFAULT_GAP_BETWEEN_BARS;
15133
    var _centerBar = false;
15134
    var _alwaysUseRounding = false;
15135
15136
    var _barWidth;
15137
15138
    dc.override(_chart, 'rescale', function () {
15139
        _chart._rescale();
15140
        _barWidth = undefined;
15141
    });
15142
15143
    dc.override(_chart, 'render', function () {
15144
        if (_chart.round() && _centerBar && !_alwaysUseRounding) {
15145
            dc.logger.warn('By default, brush rounding is disabled if bars are centered. ' +
15146
                         'See dc.js bar chart API documentation for details.');
15147
        }
15148
15149
        _chart._render();
15150
    });
15151
15152
    _chart.plotData = function () {
15153
        var layers = _chart.chartBodyG().selectAll('g.stack')
15154
            .data(_chart.data());
15155
15156
        calculateBarWidth();
15157
15158
        layers
15159
            .enter()
15160
            .append('g')
15161
            .attr('class', function (d, i) {
15162
                return 'stack ' + '_' + i;
15163
            });
15164
15165
        layers.each(function (d, i) {
15166
            var layer = d3.select(this);
15167
15168
            renderBars(layer, i, d);
15169
        });
15170
    };
15171
15172
    function barHeight(d) {
15173
        return dc.utils.safeNumber(Math.abs(_chart.y()(d.y + d.y0) - _chart.y()(d.y0)));
15174
    }
15175
15176
    function renderBars(layer, layerIndex, d) {
15177
        var bars = layer.selectAll('rect.bar')
15178
            .data(d.values, dc.pluck('x'));
15179
15180
        var enter = bars.enter()
15181
            .append('rect')
15182
            .attr('class', 'bar')
15183
            .attr('fill', dc.pluck('data', _chart.getColor))
15184
            .attr('y', _chart.yAxisHeight())
15185
            .attr('height', 0);
15186
15187
        if (_chart.renderTitle()) {
15188
            enter.append('title').text(dc.pluck('data', _chart.title(d.name)));
15189
        }
15190
15191
        if (_chart.isOrdinal()) {
15192
            bars.on('click', _chart.onClick);
15193
        }
15194
15195
        dc.transition(bars, _chart.transitionDuration())
15196
            .attr('x', function (d) {
15197
                var x = _chart.x()(d.x);
15198
                if (_centerBar) {
15199
                    x -= _barWidth / 2;
15200
                }
15201
                if (_chart.isOrdinal() && _gap !== undefined) {
15202
                    x += _gap / 2;
15203
                }
15204
                return dc.utils.safeNumber(x);
15205
            })
15206
            .attr('y', function (d) {
15207
                var y = _chart.y()(d.y + d.y0);
15208
15209
                if (d.y < 0) {
15210
                    y -= barHeight(d);
15211
                }
15212
15213
                return dc.utils.safeNumber(y);
15214
            })
15215
            .attr('width', _barWidth)
15216
            .attr('height', function (d) {
15217
                return barHeight(d);
15218
            })
15219
            .attr('fill', dc.pluck('data', _chart.getColor))
15220
            .select('title').text(dc.pluck('data', _chart.title(d.name)));
15221
15222
        dc.transition(bars.exit(), _chart.transitionDuration())
15223
            .attr('height', 0)
15224
            .remove();
15225
    }
15226
15227
    function calculateBarWidth() {
15228
        if (_barWidth === undefined) {
15229
            var numberOfBars = _chart.xUnitCount();
15230
15231
            // please can't we always use rangeBands for bar charts?
15232
            if (_chart.isOrdinal() && _gap === undefined) {
15233
                _barWidth = Math.floor(_chart.x().rangeBand());
15234
            } else if (_gap) {
15235
                _barWidth = Math.floor((_chart.xAxisLength() - (numberOfBars - 1) * _gap) / numberOfBars);
15236
            } else {
15237
                _barWidth = Math.floor(_chart.xAxisLength() / (1 + _chart.barPadding()) / numberOfBars);
15238
            }
15239
15240
            if (_barWidth === Infinity || isNaN(_barWidth) || _barWidth < MIN_BAR_WIDTH) {
15241
                _barWidth = MIN_BAR_WIDTH;
15242
            }
15243
        }
15244
    }
15245
15246
    _chart.fadeDeselectedArea = function () {
15247
        var bars = _chart.chartBodyG().selectAll('rect.bar');
15248
        var extent = _chart.brush().extent();
15249
15250
        if (_chart.isOrdinal()) {
15251
            if (_chart.hasFilter()) {
15252
                bars.classed(dc.constants.SELECTED_CLASS, function (d) {
15253
                    return _chart.hasFilter(d.x);
15254
                });
15255
                bars.classed(dc.constants.DESELECTED_CLASS, function (d) {
15256
                    return !_chart.hasFilter(d.x);
15257
                });
15258
            } else {
15259
                bars.classed(dc.constants.SELECTED_CLASS, false);
15260
                bars.classed(dc.constants.DESELECTED_CLASS, false);
15261
            }
15262
        } else {
15263
            if (!_chart.brushIsEmpty(extent)) {
15264
                var start = extent[0];
15265
                var end = extent[1];
15266
15267
                bars.classed(dc.constants.DESELECTED_CLASS, function (d) {
15268
                    return d.x < start || d.x >= end;
15269
                });
15270
            } else {
15271
                bars.classed(dc.constants.DESELECTED_CLASS, false);
15272
            }
15273
        }
15274
    };
15275
15276
    /**
15277
    #### .centerBar(boolean)
15278
    Whether the bar chart will render each bar centered around the data position on x axis. Default: false
15279
15280
    **/
15281
    _chart.centerBar = function (_) {
15282
        if (!arguments.length) {
15283
            return _centerBar;
15284
        }
15285
        _centerBar = _;
15286
        return _chart;
15287
    };
15288
15289
    dc.override(_chart, 'onClick', function (d) {
15290
        _chart._onClick(d.data);
15291
    });
15292
15293
    /**
15294
    #### .barPadding([padding])
15295
    Get or set the spacing between bars as a fraction of bar size. Valid values are between 0-1.
15296
    Setting this value will also remove any previously set `gap`. See the
15297
    [d3 docs](https://github.com/mbostock/d3/wiki/Ordinal-Scales#wiki-ordinal_rangeBands)
15298
    for a visual description of how the padding is applied.
15299
    **/
15300
    _chart.barPadding = function (_) {
15301
        if (!arguments.length) {
15302
            return _chart._rangeBandPadding();
15303
        }
15304
        _chart._rangeBandPadding(_);
15305
        _gap = undefined;
15306
        return _chart;
15307
    };
15308
15309
    _chart._useOuterPadding = function () {
15310
        return _gap === undefined;
15311
    };
15312
15313
    /**
15314
    #### .outerPadding([padding])
15315
    Get or set the outer padding on an ordinal bar chart. This setting has no effect on non-ordinal charts.
15316
    Will pad the width by `padding * barWidth` on each side of the chart.
15317
15318
    Default: 0.5
15319
    **/
15320
    _chart.outerPadding = _chart._outerRangeBandPadding;
15321
15322
    /**
15323
     #### .gap(gapBetweenBars)
15324
     Manually set fixed gap (in px) between bars instead of relying on the default auto-generated
15325
     gap.  By default the bar chart implementation will calculate and set the gap automatically
15326
     based on the number of data points and the length of the x axis.
15327
15328
    **/
15329
    _chart.gap = function (_) {
15330
        if (!arguments.length) {
15331
            return _gap;
15332
        }
15333
        _gap = _;
15334
        return _chart;
15335
    };
15336
15337
    _chart.extendBrush = function () {
15338
        var extent = _chart.brush().extent();
15339
        if (_chart.round() && (!_centerBar || _alwaysUseRounding)) {
15340
            extent[0] = extent.map(_chart.round())[0];
15341
            extent[1] = extent.map(_chart.round())[1];
15342
15343
            _chart.chartBodyG().select('.brush')
15344
                .call(_chart.brush().extent(extent));
15345
        }
15346
15347
        return extent;
15348
    };
15349
15350
    /**
15351
    #### .alwaysUseRounding([boolean])
15352
    Set or get whether rounding is enabled when bars are centered.  Default: false.  If false, using
15353
    rounding with centered bars will result in a warning and rounding will be ignored.  This flag
15354
    has no effect if bars are not centered.
15355
15356
    When using standard d3.js rounding methods, the brush often doesn't align correctly with
15357
    centered bars since the bars are offset.  The rounding function must add an offset to
15358
    compensate, such as in the following example.
15359
    ```js
15360
    chart.round(function(n) {return Math.floor(n)+0.5});
15361
    ```
15362
    **/
15363
    _chart.alwaysUseRounding = function (_) {
15364
        if (!arguments.length) {
15365
            return _alwaysUseRounding;
15366
        }
15367
        _alwaysUseRounding = _;
15368
        return _chart;
15369
    };
15370
15371
    function colorFilter(color, inv) {
15372
        return function () {
15373
            var item = d3.select(this);
15374
            var match = item.attr('fill') === color;
15375
            return inv ? !match : match;
15376
        };
15377
    }
15378
15379
    _chart.legendHighlight = function (d) {
15380
        if (!_chart.isLegendableHidden(d)) {
15381
            _chart.g().selectAll('rect.bar')
15382
                .classed('highlight', colorFilter(d.color))
15383
                .classed('fadeout', colorFilter(d.color, true));
15384
        }
15385
    };
15386
15387
    _chart.legendReset = function () {
15388
        _chart.g().selectAll('rect.bar')
15389
            .classed('highlight', false)
15390
            .classed('fadeout', false);
15391
    };
15392
15393
    dc.override(_chart, 'xAxisMax', function () {
15394
        var max = this._xAxisMax();
15395
        if ('resolution' in _chart.xUnits()) {
15396
            var res = _chart.xUnits().resolution;
15397
            max += res;
15398
        }
15399
        return max;
15400
    });
15401
15402
    return _chart.anchor(parent, chartGroup);
15403
};
15404
15405
/**
15406
## Line Chart
15407
Includes [Stack Mixin](#stack-mixin), [Coordinate Grid Mixin](#coordinate-grid-mixin)
15408
15409
Concrete line/area chart implementation.
15410
15411
Examples:
15412
* [Nasdaq 100 Index](http://dc-js.github.com/dc.js/)
15413
* [Canadian City Crime Stats](http://dc-js.github.com/dc.js/crime/index.html)
15414
#### dc.lineChart(parent[, chartGroup])
15415
Create a line chart instance and attach it to the given parent element.
15416
15417
Parameters:
15418
15419
* parent : string | node | selection | compositeChart - any valid
15420
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
15421
 a dom block element such as a div; or a dom element or d3 selection.
15422
 If the line chart is a sub-chart in a [Composite Chart](#composite-chart) then pass in the parent composite
15423
 chart instance.
15424
15425
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
15426
 Interaction with a chart will only trigger events and redraws within the chart's group.
15427
15428
Returns:
15429
A newly created line chart instance
15430
15431
```js
15432
// create a line chart under #chart-container1 element using the default global chart group
15433
var chart1 = dc.lineChart('#chart-container1');
15434
// create a line chart under #chart-container2 element using chart group A
15435
var chart2 = dc.lineChart('#chart-container2', 'chartGroupA');
15436
// create a sub-chart under a composite parent chart
15437
var chart3 = dc.lineChart(compositeChart);
15438
```
15439
15440
**/
15441
dc.lineChart = function (parent, chartGroup) {
15442
    var DEFAULT_DOT_RADIUS = 5;
15443
    var TOOLTIP_G_CLASS = 'dc-tooltip';
15444
    var DOT_CIRCLE_CLASS = 'dot';
15445
    var Y_AXIS_REF_LINE_CLASS = 'yRef';
15446
    var X_AXIS_REF_LINE_CLASS = 'xRef';
15447
    var DEFAULT_DOT_OPACITY = 1e-6;
15448
15449
    var _chart = dc.stackMixin(dc.coordinateGridMixin({}));
15450
    var _renderArea = false;
15451
    var _dotRadius = DEFAULT_DOT_RADIUS;
15452
    var _dataPointRadius = null;
15453
    var _dataPointFillOpacity = DEFAULT_DOT_OPACITY;
15454
    var _dataPointStrokeOpacity = DEFAULT_DOT_OPACITY;
15455
    var _interpolate = 'linear';
15456
    var _tension = 0.7;
15457
    var _defined;
15458
    var _dashStyle;
15459
    var _xyTipsOn = true;
15460
15461
    _chart.transitionDuration(500);
15462
    _chart._rangeBandPadding(1);
15463
15464
    _chart.plotData = function () {
15465
        var chartBody = _chart.chartBodyG();
15466
        var layersList = chartBody.selectAll('g.stack-list');
15467
15468
        if (layersList.empty()) {
15469
            layersList = chartBody.append('g').attr('class', 'stack-list');
15470
        }
15471
15472
        var layers = layersList.selectAll('g.stack').data(_chart.data());
15473
15474
        var layersEnter = layers
15475
            .enter()
15476
            .append('g')
15477
            .attr('class', function (d, i) {
15478
                return 'stack ' + '_' + i;
15479
            });
15480
15481
        drawLine(layersEnter, layers);
15482
15483
        drawArea(layersEnter, layers);
15484
15485
        drawDots(chartBody, layers);
15486
    };
15487
15488
    /**
15489
     #### .interpolate([value])
15490
     Gets or sets the interpolator to use for lines drawn, by string name, allowing e.g. step
15491
     functions, splines, and cubic interpolation.  This is passed to
15492
     [d3.svg.line.interpolate](https://github.com/mbostock/d3/wiki/SVG-Shapes#line_interpolate) and
15493
     [d3.svg.area.interpolate](https://github.com/mbostock/d3/wiki/SVG-Shapes#area_interpolate),
15494
     where you can find a complete list of valid arguments
15495
     **/
15496
    _chart.interpolate = function (_) {
15497
        if (!arguments.length) {
15498
            return _interpolate;
15499
        }
15500
        _interpolate = _;
15501
        return _chart;
15502
    };
15503
15504
    /**
15505
     #### .tension([value])
15506
     Gets or sets the tension to use for lines drawn, in the range 0 to 1.
15507
     This parameter further customizes the interpolation behavior.  It is passed to
15508
     [d3.svg.line.tension](https://github.com/mbostock/d3/wiki/SVG-Shapes#line_tension) and
15509
     [d3.svg.area.tension](https://github.com/mbostock/d3/wiki/SVG-Shapes#area_tension).  Default:
15510
     0.7
15511
     **/
15512
    _chart.tension = function (_) {
15513
        if (!arguments.length) {
15514
            return _tension;
15515
        }
15516
        _tension = _;
15517
        return _chart;
15518
    };
15519
15520
    /**
15521
     #### .defined([value])
15522
     Gets or sets a function that will determine discontinuities in the line which should be
15523
     skipped: the path will be broken into separate subpaths if some points are undefined.
15524
     This function is passed to
15525
     [d3.svg.line.defined](https://github.com/mbostock/d3/wiki/SVG-Shapes#line_defined)
15526
15527
     Note: crossfilter will sometimes coerce nulls to 0, so you may need to carefully write
15528
     custom reduce functions to get this to work, depending on your data. See
15529
     https://github.com/dc-js/dc.js/issues/615#issuecomment-49089248
15530
     **/
15531
    _chart.defined = function (_) {
15532
        if (!arguments.length) {
15533
            return _defined;
15534
        }
15535
        _defined = _;
15536
        return _chart;
15537
    };
15538
15539
    /**
15540
    #### .dashStyle([array])
15541
    Set the line's d3 dashstyle. This value becomes the 'stroke-dasharray' of line. Defaults to empty
15542
    array (solid line).
15543
     ```js
15544
     // create a Dash Dot Dot Dot
15545
     chart.dashStyle([3,1,1,1]);
15546
     ```
15547
    **/
15548
    _chart.dashStyle = function (_) {
15549
        if (!arguments.length) {
15550
            return _dashStyle;
15551
        }
15552
        _dashStyle = _;
15553
        return _chart;
15554
    };
15555
15556
    /**
15557
    #### .renderArea([boolean])
15558
    Get or set render area flag. If the flag is set to true then the chart will render the area
15559
    beneath each line and the line chart effectively becomes an area chart.
15560
15561
    **/
15562
    _chart.renderArea = function (_) {
15563
        if (!arguments.length) {
15564
            return _renderArea;
15565
        }
15566
        _renderArea = _;
15567
        return _chart;
15568
    };
15569
15570
    function colors(d, i) {
15571
        return _chart.getColor.call(d, d.values, i);
15572
    }
15573
15574
    function drawLine(layersEnter, layers) {
15575
        var line = d3.svg.line()
15576
            .x(function (d) {
15577
                return _chart.x()(d.x);
15578
            })
15579
            .y(function (d) {
15580
                return _chart.y()(d.y + d.y0);
15581
            })
15582
            .interpolate(_interpolate)
15583
            .tension(_tension);
15584
        if (_defined) {
15585
            line.defined(_defined);
15586
        }
15587
15588
        var path = layersEnter.append('path')
15589
            .attr('class', 'line')
15590
            .attr('stroke', colors);
15591
        if (_dashStyle) {
15592
            path.attr('stroke-dasharray', _dashStyle);
15593
        }
15594
15595
        dc.transition(layers.select('path.line'), _chart.transitionDuration())
15596
            //.ease('linear')
15597
            .attr('stroke', colors)
15598
            .attr('d', function (d) {
15599
                return safeD(line(d.values));
15600
            });
15601
    }
15602
15603
    function drawArea(layersEnter, layers) {
15604
        if (_renderArea) {
15605
            var area = d3.svg.area()
15606
                .x(function (d) {
15607
                    return _chart.x()(d.x);
15608
                })
15609
                .y(function (d) {
15610
                    return _chart.y()(d.y + d.y0);
15611
                })
15612
                .y0(function (d) {
15613
                    return _chart.y()(d.y0);
15614
                })
15615
                .interpolate(_interpolate)
15616
                .tension(_tension);
15617
            if (_defined) {
15618
                area.defined(_defined);
15619
            }
15620
15621
            layersEnter.append('path')
15622
                .attr('class', 'area')
15623
                .attr('fill', colors)
15624
                .attr('d', function (d) {
15625
                    return safeD(area(d.values));
15626
                });
15627
15628
            dc.transition(layers.select('path.area'), _chart.transitionDuration())
15629
                //.ease('linear')
15630
                .attr('fill', colors)
15631
                .attr('d', function (d) {
15632
                    return safeD(area(d.values));
15633
                });
15634
        }
15635
    }
15636
15637
    function safeD (d) {
15638
        return (!d || d.indexOf('NaN') >= 0) ? 'M0,0' : d;
15639
    }
15640
15641
    function drawDots(chartBody, layers) {
15642
        if (!_chart.brushOn() && _chart.xyTipsOn()) {
15643
            var tooltipListClass = TOOLTIP_G_CLASS + '-list';
15644
            var tooltips = chartBody.select('g.' + tooltipListClass);
15645
15646
            if (tooltips.empty()) {
15647
                tooltips = chartBody.append('g').attr('class', tooltipListClass);
15648
            }
15649
15650
            layers.each(function (d, layerIndex) {
15651
                var points = d.values;
15652
                if (_defined) {
15653
                    points = points.filter(_defined);
15654
                }
15655
15656
                var g = tooltips.select('g.' + TOOLTIP_G_CLASS + '._' + layerIndex);
15657
                if (g.empty()) {
15658
                    g = tooltips.append('g').attr('class', TOOLTIP_G_CLASS + ' _' + layerIndex);
15659
                }
15660
15661
                createRefLines(g);
15662
15663
                var dots = g.selectAll('circle.' + DOT_CIRCLE_CLASS)
15664
                    .data(points, dc.pluck('x'));
15665
15666
                dots.enter()
15667
                    .append('circle')
15668
                    .attr('class', DOT_CIRCLE_CLASS)
15669
                    .attr('r', getDotRadius())
15670
                    .style('fill-opacity', _dataPointFillOpacity)
15671
                    .style('stroke-opacity', _dataPointStrokeOpacity)
15672
                    .on('mousemove', function () {
15673
                        var dot = d3.select(this);
15674
                        showDot(dot);
15675
                        showRefLines(dot, g);
15676
                    })
15677
                    .on('mouseout', function () {
15678
                        var dot = d3.select(this);
15679
                        hideDot(dot);
15680
                        hideRefLines(g);
15681
                    });
15682
15683
                dots
15684
                    .attr('cx', function (d) {
15685
                        return dc.utils.safeNumber(_chart.x()(d.x));
15686
                    })
15687
                    .attr('cy', function (d) {
15688
                        return dc.utils.safeNumber(_chart.y()(d.y + d.y0));
15689
                    })
15690
                    .attr('fill', _chart.getColor)
15691
                    .call(renderTitle, d);
15692
15693
                dots.exit().remove();
15694
            });
15695
        }
15696
    }
15697
15698
    function createRefLines(g) {
15699
        var yRefLine = g.select('path.' + Y_AXIS_REF_LINE_CLASS).empty() ?
15700
            g.append('path').attr('class', Y_AXIS_REF_LINE_CLASS) : g.select('path.' + Y_AXIS_REF_LINE_CLASS);
15701
        yRefLine.style('display', 'none').attr('stroke-dasharray', '5,5');
15702
15703
        var xRefLine = g.select('path.' + X_AXIS_REF_LINE_CLASS).empty() ?
15704
            g.append('path').attr('class', X_AXIS_REF_LINE_CLASS) : g.select('path.' + X_AXIS_REF_LINE_CLASS);
15705
        xRefLine.style('display', 'none').attr('stroke-dasharray', '5,5');
15706
    }
15707
15708
    function showDot(dot) {
15709
        dot.style('fill-opacity', 0.8);
15710
        dot.style('stroke-opacity', 0.8);
15711
        dot.attr('r', _dotRadius);
15712
        return dot;
15713
    }
15714
15715
    function showRefLines(dot, g) {
15716
        var x = dot.attr('cx');
15717
        var y = dot.attr('cy');
15718
        var yAxisX = (_chart._yAxisX() - _chart.margins().left);
15719
        var yAxisRefPathD = 'M' + yAxisX + ' ' + y + 'L' + (x) + ' ' + (y);
15720
        var xAxisRefPathD = 'M' + x + ' ' + _chart.yAxisHeight() + 'L' + x + ' ' + y;
15721
        g.select('path.' + Y_AXIS_REF_LINE_CLASS).style('display', '').attr('d', yAxisRefPathD);
15722
        g.select('path.' + X_AXIS_REF_LINE_CLASS).style('display', '').attr('d', xAxisRefPathD);
15723
    }
15724
15725
    function getDotRadius() {
15726
        return _dataPointRadius || _dotRadius;
15727
    }
15728
15729
    function hideDot(dot) {
15730
        dot.style('fill-opacity', _dataPointFillOpacity)
15731
            .style('stroke-opacity', _dataPointStrokeOpacity)
15732
            .attr('r', getDotRadius());
15733
    }
15734
15735
    function hideRefLines(g) {
15736
        g.select('path.' + Y_AXIS_REF_LINE_CLASS).style('display', 'none');
15737
        g.select('path.' + X_AXIS_REF_LINE_CLASS).style('display', 'none');
15738
    }
15739
15740
    function renderTitle(dot, d) {
15741
        if (_chart.renderTitle()) {
15742
            dot.selectAll('title').remove();
15743
            dot.append('title').text(dc.pluck('data', _chart.title(d.name)));
15744
        }
15745
    }
15746
15747
    /**
15748
     #### .xyTipsOn([boolean])
15749
     Turn on/off the mouseover behavior of an individual data point which renders a circle and x/y axis
15750
     dashed lines back to each respective axis.  This is ignored if the chart brush is on (`brushOn`)
15751
     Default: true
15752
     */
15753
    _chart.xyTipsOn = function (_) {
15754
        if (!arguments.length) {
15755
            return _xyTipsOn;
15756
        }
15757
        _xyTipsOn = _;
15758
        return _chart;
15759
    };
15760
15761
    /**
15762
    #### .dotRadius([dotRadius])
15763
    Get or set the radius (in px) for dots displayed on the data points. Default dot radius is 5.
15764
    **/
15765
    _chart.dotRadius = function (_) {
15766
        if (!arguments.length) {
15767
            return _dotRadius;
15768
        }
15769
        _dotRadius = _;
15770
        return _chart;
15771
    };
15772
15773
    /**
15774
    #### .renderDataPoints([options])
15775
    Always show individual dots for each datapoint.
15776
15777
    Options, if given, is an object that can contain the following:
15778
15779
    * fillOpacity (default 0.8)
15780
    * strokeOpacity (default 0.8)
15781
    * radius (default 2)
15782
15783
    If `options` is falsy, it disables data point rendering.
15784
15785
    If no `options` are provided, the current `options` values are instead returned.
15786
15787
    Example:
15788
    ```
15789
    chart.renderDataPoints({radius: 2, fillOpacity: 0.8, strokeOpacity: 0.8})
15790
    ```
15791
    **/
15792
    _chart.renderDataPoints = function (options) {
15793
        if (!arguments.length) {
15794
            return {
15795
                fillOpacity: _dataPointFillOpacity,
15796
                strokeOpacity: _dataPointStrokeOpacity,
15797
                radius: _dataPointRadius
15798
            };
15799
        } else if (!options) {
15800
            _dataPointFillOpacity = DEFAULT_DOT_OPACITY;
15801
            _dataPointStrokeOpacity = DEFAULT_DOT_OPACITY;
15802
            _dataPointRadius = null;
15803
        } else {
15804
            _dataPointFillOpacity = options.fillOpacity || 0.8;
15805
            _dataPointStrokeOpacity = options.strokeOpacity || 0.8;
15806
            _dataPointRadius = options.radius || 2;
15807
        }
15808
        return _chart;
15809
    };
15810
15811
    function colorFilter(color, dashstyle, inv) {
15812
        return function () {
15813
            var item = d3.select(this);
15814
            var match = (item.attr('stroke') === color &&
15815
                item.attr('stroke-dasharray') === ((dashstyle instanceof Array) ?
15816
                    dashstyle.join(',') : null)) || item.attr('fill') === color;
15817
            return inv ? !match : match;
15818
        };
15819
    }
15820
15821
    _chart.legendHighlight = function (d) {
15822
        if (!_chart.isLegendableHidden(d)) {
15823
            _chart.g().selectAll('path.line, path.area')
15824
                .classed('highlight', colorFilter(d.color, d.dashstyle))
15825
                .classed('fadeout', colorFilter(d.color, d.dashstyle, true));
15826
        }
15827
    };
15828
15829
    _chart.legendReset = function () {
15830
        _chart.g().selectAll('path.line, path.area')
15831
            .classed('highlight', false)
15832
            .classed('fadeout', false);
15833
    };
15834
15835
    dc.override(_chart, 'legendables', function () {
15836
        var legendables = _chart._legendables();
15837
        if (!_dashStyle) {
15838
            return legendables;
15839
        }
15840
        return legendables.map(function (l) {
15841
            l.dashstyle = _dashStyle;
15842
            return l;
15843
        });
15844
    });
15845
15846
    return _chart.anchor(parent, chartGroup);
15847
};
15848
15849
/**
15850
## Data Count Widget
15851
Includes: [Base Mixin](#base-mixin)
15852
15853
The data count widget is a simple widget designed to display the number of records selected by the
15854
current filters out of the total number of records in the data set. Once created the data count widget
15855
will automatically update the text content of the following elements under the parent element.
15856
15857
* '.total-count' - total number of records
15858
* '.filter-count' - number of records matched by the current filters
15859
15860
Examples:
15861
15862
* [Nasdaq 100 Index](http://dc-js.github.com/dc.js/)
15863
#### dc.dataCount(parent[, chartGroup])
15864
Create a data count widget and attach it to the given parent element.
15865
15866
Parameters:
15867
15868
* parent : string | node | selection - any valid
15869
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
15870
 a dom block element such as a div; or a dom element or d3 selection.
15871
* chartGroup : string (optional) - name of the chart group this widget should be placed in.
15872
 The data count widget will only react to filter changes in the chart group.
15873
15874
Returns:
15875
A newly created data count widget instance
15876
#### .dimension(allData) - **mandatory**
15877
For the data count widget the only valid dimension is the entire data set.
15878
#### .group(groupAll) - **mandatory**
15879
For the data count widget the only valid group is the group returned by `dimension.groupAll()`.
15880
15881
```js
15882
var ndx = crossfilter(data);
15883
var all = ndx.groupAll();
15884
15885
dc.dataCount('.dc-data-count')
15886
    .dimension(ndx)
15887
    .group(all);
15888
```
15889
15890
**/
15891
dc.dataCount = function (parent, chartGroup) {
15892
    var _formatNumber = d3.format(',d');
15893
    var _chart = dc.baseMixin({});
15894
    var _html = {some:'', all:''};
15895
15896
    /**
15897
     #### html([object])
15898
     Gets or sets an optional object specifying HTML templates to use depending how many items are
15899
     selected. The text `%total-count` will replaced with the total number of records, and the text
15900
     `%filter-count` will be replaced with the number of selected records.
15901
     - all: HTML template to use if all items are selected
15902
     - some: HTML template to use if not all items are selected
15903
15904
     ```js
15905
     counter.html({
15906
         some: '%filter-count out of %total-count records selected',
15907
         all: 'All records selected. Click on charts to apply filters'
15908
     })
15909
     ```
15910
     **/
15911
    _chart.html = function (s) {
15912
        if (!arguments.length) {
15913
            return _html;
15914
        }
15915
        if (s.all) {
15916
            _html.all = s.all;
15917
        }
15918
        if (s.some) {
15919
            _html.some = s.some;
15920
        }
15921
        return _chart;
15922
    };
15923
15924
    /**
15925
    #### formatNumber([formatter])
15926
    Gets or sets an optional function to format the filter count and total count.
15927
15928
    ```js
15929
    counter.formatNumber(d3.format('.2g'))
15930
    ```
15931
    **/
15932
    _chart.formatNumber = function (s) {
15933
        if (!arguments.length) {
15934
            return _formatNumber;
15935
        }
15936
        _formatNumber = s;
15937
        return _chart;
15938
    };
15939
15940
    _chart._doRender = function () {
15941
        var tot = _chart.dimension().size(),
15942
            val = _chart.group().value();
15943
        var all = _formatNumber(tot);
15944
        var selected = _formatNumber(val);
15945
15946
        if ((tot === val) && (_html.all !== '')) {
15947
            _chart.root().html(_html.all.replace('%total-count', all).replace('%filter-count', selected));
15948
        } else if (_html.some !== '') {
15949
            _chart.root().html(_html.some.replace('%total-count', all).replace('%filter-count', selected));
15950
        } else {
15951
            _chart.selectAll('.total-count').text(all);
15952
            _chart.selectAll('.filter-count').text(selected);
15953
        }
15954
        return _chart;
15955
    };
15956
15957
    _chart._doRedraw = function () {
15958
        return _chart._doRender();
15959
    };
15960
15961
    return _chart.anchor(parent, chartGroup);
15962
};
15963
15964
/**
15965
## Data Table Widget
15966
Includes: [Base Mixin](#base-mixin)
15967
15968
The data table is a simple widget designed to list crossfilter focused data set (rows being
15969
filtered) in a good old tabular fashion.
15970
15971
Examples:
15972
* [Nasdaq 100 Index](http://dc-js.github.com/dc.js/)
15973
#### dc.dataTable(parent[, chartGroup])
15974
Create a data table widget instance and attach it to the given parent element.
15975
15976
Parameters:
15977
* parent : string | node | selection - any valid
15978
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
15979
 a dom block element such as a div; or a dom element or d3 selection.
15980
15981
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
15982
 Interaction with a chart will only trigger events and redraws within the chart's group.
15983
15984
Returns:
15985
A newly created data table widget instance
15986
15987
**/
15988
dc.dataTable = function (parent, chartGroup) {
15989
    var LABEL_CSS_CLASS = 'dc-table-label';
15990
    var ROW_CSS_CLASS = 'dc-table-row';
15991
    var COLUMN_CSS_CLASS = 'dc-table-column';
15992
    var GROUP_CSS_CLASS = 'dc-table-group';
15993
    var HEAD_CSS_CLASS = 'dc-table-head';
15994
15995
    var _chart = dc.baseMixin({});
15996
15997
    var _size = 25;
15998
    var _columns = [];
15999
    var _sortBy = function (d) {
16000
        return d;
16001
    };
16002
    var _order = d3.ascending;
16003
16004
    _chart._doRender = function () {
16005
        _chart.selectAll('tbody').remove();
16006
16007
        renderRows(renderGroups());
16008
16009
        return _chart;
16010
    };
16011
16012
    _chart._doColumnValueFormat = function (v, d) {
16013
        return ((typeof v === 'function') ?
16014
                v(d) :                          // v as function
16015
                ((typeof v === 'string') ?
16016
                 d[v] :                         // v is field name string
16017
                 v.format(d)                        // v is Object, use fn (element 2)
16018
                )
16019
               );
16020
    };
16021
16022
    _chart._doColumnHeaderFormat = function (d) {
16023
        // if 'function', convert to string representation
16024
        // show a string capitalized
16025
        // if an object then display it's label string as-is.
16026
        return (typeof d === 'function') ?
16027
                _chart._doColumnHeaderFnToString(d) :
16028
                ((typeof d === 'string') ?
16029
                 _chart._doColumnHeaderCapitalize(d) : String(d.label));
16030
    };
16031
16032
    _chart._doColumnHeaderCapitalize = function (s) {
16033
        // capitalize
16034
        return s.charAt(0).toUpperCase() + s.slice(1);
16035
    };
16036
16037
    _chart._doColumnHeaderFnToString = function (f) {
16038
        // columnString(f) {
16039
        var s = String(f);
16040
        var i1 = s.indexOf('return ');
16041
        if (i1 >= 0) {
16042
            var i2 = s.lastIndexOf(';');
16043
            if (i2 >= 0) {
16044
                s = s.substring(i1 + 7, i2);
16045
                var i3 = s.indexOf('numberFormat');
16046
                if (i3 >= 0) {
16047
                    s = s.replace('numberFormat', '');
16048
                }
16049
            }
16050
        }
16051
        return s;
16052
    };
16053
16054
    function renderGroups() {
16055
        // The 'original' example uses all 'functions'.
16056
	// If all 'functions' are used, then don't remove/add a header, and leave
16057
	// the html alone. This preserves the functionality of earlier releases.
16058
	// A 2nd option is a string representing a field in the data.
16059
	// A third option is to supply an Object such as an array of 'information', and
16060
	// supply your own _doColumnHeaderFormat and _doColumnValueFormat functions to
16061
	// create what you need.
16062
        var bAllFunctions = true;
16063
        _columns.forEach(function (f) {
16064
            bAllFunctions = bAllFunctions & (typeof f === 'function');
16065
        });
16066
16067
        if (!bAllFunctions) {
16068
            _chart.selectAll('th').remove();
16069
            var headcols = _chart.root().selectAll('th')
16070
                .data(_columns);
16071
16072
            var headGroup = headcols
16073
                .enter()
16074
                .append('th');
16075
16076
            headGroup
16077
                .attr('class', HEAD_CSS_CLASS)
16078
                    .html(function (d) {
16079
                        return (_chart._doColumnHeaderFormat(d));
16080
16081
                    });
16082
        }
16083
16084
        var groups = _chart.root().selectAll('tbody')
16085
            .data(nestEntries(), function (d) {
16086
                return _chart.keyAccessor()(d);
16087
            });
16088
16089
        var rowGroup = groups
16090
            .enter()
16091
            .append('tbody');
16092
16093
        rowGroup
16094
            .append('tr')
16095
            .attr('class', GROUP_CSS_CLASS)
16096
                .append('td')
16097
                .attr('class', LABEL_CSS_CLASS)
16098
                .attr('colspan', _columns.length)
16099
                .html(function (d) {
16100
                    return _chart.keyAccessor()(d);
16101
                });
16102
16103
        groups.exit().remove();
16104
16105
        return rowGroup;
16106
    }
16107
16108
    function nestEntries() {
16109
        var entries;
16110
        if (_order === d3.ascending) {
16111
            entries = _chart.dimension().bottom(_size);
16112
        } else {
16113
            entries = _chart.dimension().top(_size);
16114
        }
16115
16116
        return d3.nest()
16117
            .key(_chart.group())
16118
            .sortKeys(_order)
16119
            .entries(entries.sort(function (a, b) {
16120
                return _order(_sortBy(a), _sortBy(b));
16121
            }));
16122
    }
16123
16124
    function renderRows(groups) {
16125
        var rows = groups.order()
16126
            .selectAll('tr.' + ROW_CSS_CLASS)
16127
            .data(function (d) {
16128
                return d.values;
16129
            });
16130
16131
        var rowEnter = rows.enter()
16132
            .append('tr')
16133
            .attr('class', ROW_CSS_CLASS);
16134
16135
        _columns.forEach(function (v, i) {
16136
            rowEnter.append('td')
16137
                .attr('class', COLUMN_CSS_CLASS + ' _' + i)
16138
                .html(function (d) {
16139
                    return _chart._doColumnValueFormat(v, d);
16140
                });
16141
        });
16142
16143
        rows.exit().remove();
16144
16145
        return rows;
16146
    }
16147
16148
    _chart._doRedraw = function () {
16149
        return _chart._doRender();
16150
    };
16151
16152
    /**
16153
    #### .size([size])
16154
    Get or set the table size which determines the number of rows displayed by the widget.
16155
16156
    **/
16157
    _chart.size = function (s) {
16158
        if (!arguments.length) {
16159
            return _size;
16160
        }
16161
        _size = s;
16162
        return _chart;
16163
    };
16164
16165
    /**
16166
    #### .columns([columnFunctionArray])
16167
    Get or set column functions. The data table widget now supports several methods of specifying
16168
    the columns to display.  The original method, first shown below, uses an array of functions to
16169
    generate dynamic columns. Column functions are simple javascript functions with only one input
16170
    argument `d` which represents a row in the data set. The return value of these functions will be
16171
    used directly to generate table content for each cell. However, this method requires the .html
16172
    table entry to have a fixed set of column headers.
16173
16174
    ```js
16175
        chart.columns([
16176
            function(d) {
16177
                return d.date;
16178
            },
16179
            function(d) {
16180
                return d.open;
16181
            },
16182
            function(d) {
16183
                return d.close;
16184
            },
16185
            function(d) {
16186
                return numberFormat(d.close - d.open);
16187
            },
16188
            function(d) {
16189
                return d.volume;
16190
            }
16191
        ]);
16192
    ```
16193
16194
    The next example shows you can simply list the data (d) content directly without
16195
    specifying it as a function, except where necessary (ie, computed columns).  Note
16196
    the data element accessor name is capitalized when displayed in the table. You can
16197
    also mix in functions as desired or necessary, but you must use the
16198
        Object = [Label, Fn] method as shown below.
16199
    You may wish to override the following two functions, which are internally used to
16200
    translate the column information or function into a displayed header. The first one
16201
    is used on the simple "string" column specifier, the second is used to transform the
16202
    String(fn) into something displayable. For the Stock example, the function for Change
16203
    becomes a header of 'd.close - d.open'.
16204
        _chart._doColumnHeaderCapitalize _chart._doColumnHeaderFnToString
16205
    You may use your own Object definition, however you must then override
16206
        _chart._doColumnHeaderFormat , _chart._doColumnValueFormat
16207
    Be aware that fields without numberFormat specification will be displayed just as
16208
    they are stored in the data, unformatted.
16209
    ```js
16210
        chart.columns([
16211
                "date",    // d["date"], ie, a field accessor; capitalized automatically
16212
                "open",    // ...
16213
                "close",   // ...
16214
                ["Change", // Specify an Object = [Label, Fn]
16215
                      function (d) {
16216
                          return numberFormat(d.close - d.open);
16217
                      }],
16218
                "volume"   // d["volume"], ie, a field accessor; capitalized automatically
16219
        ]);
16220
    ```
16221
16222
    A third example, where all fields are specified using the Object = [Label, Fn] method.
16223
16224
    ```js
16225
        chart.columns([
16226
            ["Date",   // Specify an Object = [Label, Fn]
16227
             function (d) {
16228
                 return d.date;
16229
             }],
16230
            ["Open",
16231
             function (d) {
16232
                 return numberFormat(d.open);
16233
             }],
16234
            ["Close",
16235
             function (d) {
16236
                 return numberFormat(d.close);
16237
             }],
16238
            ["Change",
16239
             function (d) {
16240
                 return numberFormat(d.close - d.open);
16241
             }],
16242
            ["Volume",
16243
             function (d) {
16244
                 return d.volume;
16245
             }]
16246
        ]);
16247
    ```
16248
16249
    **/
16250
    _chart.columns = function (_) {
16251
        if (!arguments.length) {
16252
            return _columns;
16253
        }
16254
        _columns = _;
16255
        return _chart;
16256
    };
16257
16258
    /**
16259
    #### .sortBy([sortByFunction])
16260
    Get or set sort-by function. This function works as a value accessor at row level and returns a
16261
    particular field to be sorted by. Default value: identity function
16262
16263
    ```js
16264
       chart.sortBy(function(d) {
16265
            return d.date;
16266
        });
16267
    ```
16268
16269
    **/
16270
    _chart.sortBy = function (_) {
16271
        if (!arguments.length) {
16272
            return _sortBy;
16273
        }
16274
        _sortBy = _;
16275
        return _chart;
16276
    };
16277
16278
    /**
16279
    #### .order([order])
16280
    Get or set sort order. Default value: ``` d3.ascending ```
16281
16282
    ```js
16283
        chart.order(d3.descending);
16284
    ```
16285
16286
    **/
16287
    _chart.order = function (_) {
16288
        if (!arguments.length) {
16289
            return _order;
16290
        }
16291
        _order = _;
16292
        return _chart;
16293
    };
16294
16295
    return _chart.anchor(parent, chartGroup);
16296
};
16297
16298
/**
16299
 ## Data Grid Widget
16300
16301
 Includes: [Base Mixin](#base-mixin)
16302
16303
 Data grid is a simple widget designed to list the filtered records, providing
16304
 a simple way to define how the items are displayed.
16305
16306
 Examples:
16307
 * [List of members of the european parliament](http://europarl.me/dc.js/web/ep/index.html)
16308
16309
 #### dc.dataGrid(parent[, chartGroup])
16310
 Create a data grid widget instance and attach it to the given parent element.
16311
16312
Parameters:
16313
* parent : string | node | selection - any valid
16314
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
16315
 a dom block element such as a div; or a dom element or d3 selection.
16316
16317
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
16318
 Interaction with a chart will only trigger events and redraws within the chart's group.
16319
16320
Returns:
16321
A newly created data grid widget instance
16322
16323
 **/
16324
dc.dataGrid = function (parent, chartGroup) {
16325
    var LABEL_CSS_CLASS = 'dc-grid-label';
16326
    var ITEM_CSS_CLASS = 'dc-grid-item';
16327
    var GROUP_CSS_CLASS = 'dc-grid-group';
16328
    var GRID_CSS_CLASS = 'dc-grid-top';
16329
16330
    var _chart = dc.baseMixin({});
16331
16332
    var _size = 999; // shouldn't be needed, but you might
16333
    var _html = function (d) { return 'you need to provide an html() handling param:  ' + JSON.stringify(d); };
16334
    var _sortBy = function (d) {
16335
        return d;
16336
    };
16337
    var _order = d3.ascending;
16338
16339
    var _htmlGroup = function (d) {
16340
        return '<div class=\'' + GROUP_CSS_CLASS + '\'><h1 class=\'' + LABEL_CSS_CLASS + '\'>' +
16341
            _chart.keyAccessor()(d) + '</h1></div>';
16342
    };
16343
16344
    _chart._doRender = function () {
16345
        _chart.selectAll('div.' + GRID_CSS_CLASS).remove();
16346
16347
        renderItems(renderGroups());
16348
16349
        return _chart;
16350
    };
16351
16352
    function renderGroups() {
16353
        var groups = _chart.root().selectAll('div.' + GRID_CSS_CLASS)
16354
                .data(nestEntries(), function (d) {
16355
                    return _chart.keyAccessor()(d);
16356
                });
16357
16358
        var itemGroup = groups
16359
                .enter()
16360
                .append('div')
16361
                .attr('class', GRID_CSS_CLASS);
16362
16363
        if (_htmlGroup) {
16364
            itemGroup
16365
                .html(function (d) {
16366
                    return _htmlGroup(d);
16367
                });
16368
        }
16369
16370
        groups.exit().remove();
16371
        return itemGroup;
16372
    }
16373
16374
    function nestEntries() {
16375
        var entries = _chart.dimension().top(_size);
16376
16377
        return d3.nest()
16378
            .key(_chart.group())
16379
            .sortKeys(_order)
16380
            .entries(entries.sort(function (a, b) {
16381
                return _order(_sortBy(a), _sortBy(b));
16382
            }));
16383
    }
16384
16385
    function renderItems(groups) {
16386
        var items = groups.order()
16387
                .selectAll('div.' + ITEM_CSS_CLASS)
16388
                .data(function (d) {
16389
                    return d.values;
16390
                });
16391
16392
        items.enter()
16393
            .append('div')
16394
            .attr('class', ITEM_CSS_CLASS)
16395
            .html(function (d) {
16396
                return _html(d);
16397
            });
16398
16399
        items.exit().remove();
16400
16401
        return items;
16402
    }
16403
16404
    _chart._doRedraw = function () {
16405
        return _chart._doRender();
16406
    };
16407
16408
    /**
16409
     #### .size([size])
16410
     Get or set the grid size which determines the number of items displayed by the widget.
16411
16412
     **/
16413
    _chart.size = function (s) {
16414
        if (!arguments.length) {
16415
            return _size;
16416
        }
16417
        _size = s;
16418
        return _chart;
16419
    };
16420
16421
    /**
16422
     #### .html( function (data) { return '<html>'; })
16423
     Get or set the function that formats an item. The data grid widget uses a
16424
     function to generate dynamic html. Use your favourite templating engine or
16425
     generate the string directly.
16426
     ```js
16427
     chart.html(function (d) { return '<div class='item '+data.exampleCategory+''>'+data.exampleString+'</div>';});
16428
     ```
16429
16430
     **/
16431
    _chart.html = function (_) {
16432
        if (!arguments.length) {
16433
            return _html;
16434
        }
16435
        _html = _;
16436
        return _chart;
16437
    };
16438
16439
    /**
16440
     #### .htmlGroup( function (data) { return '<html>'; })
16441
     Get or set the function that formats a group label.
16442
     ```js
16443
     chart.htmlGroup (function (d) { return '<h2>'.d.key . 'with ' . d.values.length .' items</h2>'});
16444
     ```
16445
16446
     **/
16447
    _chart.htmlGroup = function (_) {
16448
        if (!arguments.length) {
16449
            return _htmlGroup;
16450
        }
16451
        _htmlGroup = _;
16452
        return _chart;
16453
    };
16454
16455
    /**
16456
     #### .sortBy([sortByFunction])
16457
     Get or set sort-by function. This function works as a value accessor at the item
16458
     level and returns a particular field to be sorted.
16459
     by. Default: identity function
16460
16461
     ```js
16462
     chart.sortBy(function(d) {
16463
         return d.date;
16464
     });
16465
     ```
16466
16467
     **/
16468
    _chart.sortBy = function (_) {
16469
        if (!arguments.length) {
16470
            return _sortBy;
16471
        }
16472
        _sortBy = _;
16473
        return _chart;
16474
    };
16475
16476
    /**
16477
     #### .order([order])
16478
     Get or set sort order function. Default value: ``` d3.ascending ```
16479
16480
     ```js
16481
     chart.order(d3.descending);
16482
     ```
16483
16484
     **/
16485
    _chart.order = function (_) {
16486
        if (!arguments.length) {
16487
            return _order;
16488
        }
16489
        _order = _;
16490
        return _chart;
16491
    };
16492
16493
    return _chart.anchor(parent, chartGroup);
16494
};
16495
16496
/**
16497
## Bubble Chart
16498
Includes: [Bubble Mixin](#bubble-mixin), [Coordinate Grid Mixin](#coordinate-grid-mixin)
16499
16500
A concrete implementation of a general purpose bubble chart that allows data visualization using the
16501
following dimensions:
16502
16503
* x axis position
16504
* y axis position
16505
* bubble radius
16506
* color
16507
16508
Examples:
16509
* [Nasdaq 100 Index](http://dc-js.github.com/dc.js/)
16510
* [US Venture Capital Landscape 2011](http://dc-js.github.com/dc.js/vc/index.html)
16511
#### dc.bubbleChart(parent[, chartGroup])
16512
Create a bubble chart instance and attach it to the given parent element.
16513
16514
Parameters:
16515
* parent : string | node | selection | compositeChart - any valid
16516
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
16517
 a dom block element such as a div; or a dom element or d3 selection.
16518
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
16519
 Interaction with a chart will only trigger events and redraws within the chart's group.
16520
16521
Returns:
16522
A newly created bubble chart instance
16523
16524
```js
16525
// create a bubble chart under #chart-container1 element using the default global chart group
16526
var bubbleChart1 = dc.bubbleChart('#chart-container1');
16527
// create a bubble chart under #chart-container2 element using chart group A
16528
var bubbleChart2 = dc.bubbleChart('#chart-container2', 'chartGroupA');
16529
```
16530
16531
**/
16532
dc.bubbleChart = function (parent, chartGroup) {
16533
    var _chart = dc.bubbleMixin(dc.coordinateGridMixin({}));
16534
16535
    var _elasticRadius = false;
16536
16537
    _chart.transitionDuration(750);
16538
16539
    var bubbleLocator = function (d) {
16540
        return 'translate(' + (bubbleX(d)) + ',' + (bubbleY(d)) + ')';
16541
    };
16542
16543
    /**
16544
    #### .elasticRadius([boolean])
16545
    Turn on or off the elastic bubble radius feature, or return the value of the flag. If this
16546
    feature is turned on, then bubble radii will be automatically rescaled to fit the chart better.
16547
16548
    **/
16549
    _chart.elasticRadius = function (_) {
16550
        if (!arguments.length) {
16551
            return _elasticRadius;
16552
        }
16553
        _elasticRadius = _;
16554
        return _chart;
16555
    };
16556
16557
    _chart.plotData = function () {
16558
        if (_elasticRadius) {
16559
            _chart.r().domain([_chart.rMin(), _chart.rMax()]);
16560
        }
16561
16562
        _chart.r().range([_chart.MIN_RADIUS, _chart.xAxisLength() * _chart.maxBubbleRelativeSize()]);
16563
16564
        var bubbleG = _chart.chartBodyG().selectAll('g.' + _chart.BUBBLE_NODE_CLASS)
16565
            .data(_chart.data(), function (d) { return d.key; });
16566
16567
        renderNodes(bubbleG);
16568
16569
        updateNodes(bubbleG);
16570
16571
        removeNodes(bubbleG);
16572
16573
        _chart.fadeDeselectedArea();
16574
    };
16575
16576
    function renderNodes(bubbleG) {
16577
        var bubbleGEnter = bubbleG.enter().append('g');
16578
16579
        bubbleGEnter
16580
            .attr('class', _chart.BUBBLE_NODE_CLASS)
16581
            .attr('transform', bubbleLocator)
16582
            .append('circle').attr('class', function (d, i) {
16583
                return _chart.BUBBLE_CLASS + ' _' + i;
16584
            })
16585
            .on('click', _chart.onClick)
16586
            .attr('fill', _chart.getColor)
16587
            .attr('r', 0);
16588
        dc.transition(bubbleG, _chart.transitionDuration())
16589
            .selectAll('circle.' + _chart.BUBBLE_CLASS)
16590
            .attr('r', function (d) {
16591
                return _chart.bubbleR(d);
16592
            })
16593
            .attr('opacity', function (d) {
16594
                return (_chart.bubbleR(d) > 0) ? 1 : 0;
16595
            });
16596
16597
        _chart._doRenderLabel(bubbleGEnter);
16598
16599
        _chart._doRenderTitles(bubbleGEnter);
16600
    }
16601
16602
    function updateNodes(bubbleG) {
16603
        dc.transition(bubbleG, _chart.transitionDuration())
16604
            .attr('transform', bubbleLocator)
16605
            .selectAll('circle.' + _chart.BUBBLE_CLASS)
16606
            .attr('fill', _chart.getColor)
16607
            .attr('r', function (d) {
16608
                return _chart.bubbleR(d);
16609
            })
16610
            .attr('opacity', function (d) {
16611
                return (_chart.bubbleR(d) > 0) ? 1 : 0;
16612
            });
16613
16614
        _chart.doUpdateLabels(bubbleG);
16615
        _chart.doUpdateTitles(bubbleG);
16616
    }
16617
16618
    function removeNodes(bubbleG) {
16619
        bubbleG.exit().remove();
16620
    }
16621
16622
    function bubbleX(d) {
16623
        var x = _chart.x()(_chart.keyAccessor()(d));
16624
        if (isNaN(x)) {
16625
            x = 0;
16626
        }
16627
        return x;
16628
    }
16629
16630
    function bubbleY(d) {
16631
        var y = _chart.y()(_chart.valueAccessor()(d));
16632
        if (isNaN(y)) {
16633
            y = 0;
16634
        }
16635
        return y;
16636
    }
16637
16638
    _chart.renderBrush = function () {
16639
        // override default x axis brush from parent chart
16640
    };
16641
16642
    _chart.redrawBrush = function () {
16643
        // override default x axis brush from parent chart
16644
        _chart.fadeDeselectedArea();
16645
    };
16646
16647
    return _chart.anchor(parent, chartGroup);
16648
};
16649
16650
/**
16651
## Composite Chart
16652
Includes: [Coordinate Grid Mixin](#coordinate-grid-mixin)
16653
16654
Composite charts are a special kind of chart that render multiple charts on the same Coordinate
16655
Grid. You can overlay (compose) different bar/line/area charts in a single composite chart to
16656
achieve some quite flexible charting effects.
16657
#### dc.compositeChart(parent[, chartGroup])
16658
Create a composite chart instance and attach it to the given parent element.
16659
16660
Parameters:
16661
* parent : string | node | selection - any valid
16662
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
16663
 a dom block element such as a div; or a dom element or d3 selection.
16664
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
16665
 Interaction with a chart will only trigger events and redraws within the chart's group.
16666
16667
Returns:
16668
A newly created composite chart instance
16669
16670
```js
16671
// create a composite chart under #chart-container1 element using the default global chart group
16672
var compositeChart1 = dc.compositeChart('#chart-container1');
16673
// create a composite chart under #chart-container2 element using chart group A
16674
var compositeChart2 = dc.compositeChart('#chart-container2', 'chartGroupA');
16675
```
16676
16677
**/
16678
dc.compositeChart = function (parent, chartGroup) {
16679
16680
    var SUB_CHART_CLASS = 'sub';
16681
    var DEFAULT_RIGHT_Y_AXIS_LABEL_PADDING = 12;
16682
16683
    var _chart = dc.coordinateGridMixin({});
16684
    var _children = [];
16685
16686
    var _childOptions = {};
16687
16688
    var _shareColors = false,
16689
        _shareTitle = true;
16690
16691
    var _rightYAxis = d3.svg.axis(),
16692
        _rightYAxisLabel = 0,
16693
        _rightYAxisLabelPadding = DEFAULT_RIGHT_Y_AXIS_LABEL_PADDING,
16694
        _rightY,
16695
        _rightAxisGridLines = false;
16696
16697
    _chart._mandatoryAttributes([]);
16698
    _chart.transitionDuration(500);
16699
16700
    dc.override(_chart, '_generateG', function () {
16701
        var g = this.__generateG();
16702
16703
        for (var i = 0; i < _children.length; ++i) {
16704
            var child = _children[i];
16705
16706
            generateChildG(child, i);
16707
16708
            if (!child.dimension()) {
16709
                child.dimension(_chart.dimension());
16710
            }
16711
            if (!child.group()) {
16712
                child.group(_chart.group());
16713
            }
16714
16715
            child.chartGroup(_chart.chartGroup());
16716
            child.svg(_chart.svg());
16717
            child.xUnits(_chart.xUnits());
16718
            child.transitionDuration(_chart.transitionDuration());
16719
            child.brushOn(_chart.brushOn());
16720
            child.renderTitle(_chart.renderTitle());
16721
            child.elasticX(_chart.elasticX());
16722
        }
16723
16724
        return g;
16725
    });
16726
16727
    _chart._brushing = function () {
16728
        var extent = _chart.extendBrush();
16729
        var brushIsEmpty = _chart.brushIsEmpty(extent);
16730
16731
        for (var i = 0; i < _children.length; ++i) {
16732
            _children[i].filter(null);
16733
            if (!brushIsEmpty) {
16734
                _children[i].filter(extent);
16735
            }
16736
        }
16737
    };
16738
16739
    _chart._prepareYAxis = function () {
16740
        if (leftYAxisChildren().length !== 0) { prepareLeftYAxis(); }
16741
        if (rightYAxisChildren().length !== 0) { prepareRightYAxis(); }
16742
16743
        if (leftYAxisChildren().length > 0 && !_rightAxisGridLines) {
16744
            _chart._renderHorizontalGridLinesForAxis(_chart.g(), _chart.y(), _chart.yAxis());
16745
        }
16746
        else if (rightYAxisChildren().length > 0) {
16747
            _chart._renderHorizontalGridLinesForAxis(_chart.g(), _rightY, _rightYAxis);
16748
        }
16749
    };
16750
16751
    _chart.renderYAxis = function () {
16752
        if (leftYAxisChildren().length !== 0) {
16753
            _chart.renderYAxisAt('y', _chart.yAxis(), _chart.margins().left);
16754
            _chart.renderYAxisLabel('y', _chart.yAxisLabel(), -90);
16755
        }
16756
16757
        if (rightYAxisChildren().length !== 0) {
16758
            _chart.renderYAxisAt('yr', _chart.rightYAxis(), _chart.width() - _chart.margins().right);
16759
            _chart.renderYAxisLabel('yr', _chart.rightYAxisLabel(), 90, _chart.width() - _rightYAxisLabelPadding);
16760
        }
16761
    };
16762
16763
    function prepareRightYAxis() {
16764
        if (_chart.rightY() === undefined || _chart.elasticY()) {
16765
            _chart.rightY(d3.scale.linear());
16766
            _chart.rightY().domain([rightYAxisMin(), rightYAxisMax()]).rangeRound([_chart.yAxisHeight(), 0]);
16767
        }
16768
16769
        _chart.rightY().range([_chart.yAxisHeight(), 0]);
16770
        _chart.rightYAxis(_chart.rightYAxis().scale(_chart.rightY()));
16771
16772
        _chart.rightYAxis().orient('right');
16773
    }
16774
16775
    function prepareLeftYAxis() {
16776
        if (_chart.y() === undefined || _chart.elasticY()) {
16777
            _chart.y(d3.scale.linear());
16778
            _chart.y().domain([yAxisMin(), yAxisMax()]).rangeRound([_chart.yAxisHeight(), 0]);
16779
        }
16780
16781
        _chart.y().range([_chart.yAxisHeight(), 0]);
16782
        _chart.yAxis(_chart.yAxis().scale(_chart.y()));
16783
16784
        _chart.yAxis().orient('left');
16785
    }
16786
16787
    function generateChildG(child, i) {
16788
        child._generateG(_chart.g());
16789
        child.g().attr('class', SUB_CHART_CLASS + ' _' + i);
16790
    }
16791
16792
    _chart.plotData = function () {
16793
        for (var i = 0; i < _children.length; ++i) {
16794
            var child = _children[i];
16795
16796
            if (!child.g()) {
16797
                generateChildG(child, i);
16798
            }
16799
16800
            if (_shareColors) {
16801
                child.colors(_chart.colors());
16802
            }
16803
16804
            child.x(_chart.x());
16805
16806
            child.xAxis(_chart.xAxis());
16807
16808
            if (child.useRightYAxis()) {
16809
                child.y(_chart.rightY());
16810
                child.yAxis(_chart.rightYAxis());
16811
            }
16812
            else {
16813
                child.y(_chart.y());
16814
                child.yAxis(_chart.yAxis());
16815
            }
16816
16817
            child.plotData();
16818
16819
            child._activateRenderlets();
16820
        }
16821
    };
16822
16823
    /**
16824
    #### .useRightAxisGridLines(bool)
16825
    Get or set whether to draw gridlines from the right y axis.  Drawing from the left y axis is the
16826
    default behavior. This option is only respected when subcharts with both left and right y-axes
16827
    are present.
16828
    **/
16829
    _chart.useRightAxisGridLines = function (_) {
16830
        if (!arguments) {
16831
            return _rightAxisGridLines;
16832
        }
16833
16834
        _rightAxisGridLines = _;
16835
        return _chart;
16836
    };
16837
16838
    /**
16839
    #### .childOptions({object})
16840
    Get or set chart-specific options for all child charts. This is equivalent to calling `.options`
16841
    on each child chart.
16842
    **/
16843
    _chart.childOptions = function (_) {
16844
        if (!arguments.length) {
16845
            return _childOptions;
16846
        }
16847
        _childOptions = _;
16848
        _children.forEach(function (child) {
16849
            child.options(_childOptions);
16850
        });
16851
        return _chart;
16852
    };
16853
16854
    _chart.fadeDeselectedArea = function () {
16855
        for (var i = 0; i < _children.length; ++i) {
16856
            var child = _children[i];
16857
            child.brush(_chart.brush());
16858
            child.fadeDeselectedArea();
16859
        }
16860
    };
16861
16862
    /**
16863
    #### .rightYAxisLabel([labelText])
16864
    Set or get the right y axis label.
16865
    **/
16866
    _chart.rightYAxisLabel = function (_, padding) {
16867
        if (!arguments.length) {
16868
            return _rightYAxisLabel;
16869
        }
16870
        _rightYAxisLabel = _;
16871
        _chart.margins().right -= _rightYAxisLabelPadding;
16872
        _rightYAxisLabelPadding = (padding === undefined) ? DEFAULT_RIGHT_Y_AXIS_LABEL_PADDING : padding;
16873
        _chart.margins().right += _rightYAxisLabelPadding;
16874
        return _chart;
16875
    };
16876
16877
    /**
16878
    #### .compose(subChartArray)
16879
    Combine the given charts into one single composite coordinate grid chart.
16880
16881
    ```js
16882
    // compose the given charts in the array into one single composite chart
16883
    moveChart.compose([
16884
        // when creating sub-chart you need to pass in the parent chart
16885
        dc.lineChart(moveChart)
16886
            .group(indexAvgByMonthGroup) // if group is missing then parent's group will be used
16887
            .valueAccessor(function (d){return d.value.avg;})
16888
            // most of the normal functions will continue to work in a composed chart
16889
            .renderArea(true)
16890
            .stack(monthlyMoveGroup, function (d){return d.value;})
16891
            .title(function (d){
16892
                var value = d.value.avg?d.value.avg:d.value;
16893
                if(isNaN(value)) value = 0;
16894
                return dateFormat(d.key) + '\n' + numberFormat(value);
16895
            }),
16896
        dc.barChart(moveChart)
16897
            .group(volumeByMonthGroup)
16898
            .centerBar(true)
16899
    ]);
16900
    ```
16901
16902
    **/
16903
    _chart.compose = function (charts) {
16904
        _children = charts;
16905
        _children.forEach(function (child) {
16906
            child.height(_chart.height());
16907
            child.width(_chart.width());
16908
            child.margins(_chart.margins());
16909
16910
            if (_shareTitle) {
16911
                child.title(_chart.title());
16912
            }
16913
16914
            child.options(_childOptions);
16915
        });
16916
        return _chart;
16917
    };
16918
16919
    /**
16920
     #### .children()
16921
     Returns the child charts which are composed into the composite chart.
16922
     **/
16923
16924
    _chart.children = function () {
16925
        return _children;
16926
    };
16927
16928
    /**
16929
    #### .shareColors([boolean])
16930
    Get or set color sharing for the chart. If set, the `.colors()` value from this chart
16931
    will be shared with composed children. Additionally if the child chart implements
16932
    Stackable and has not set a custom .colorAccessor, then it will generate a color
16933
    specific to its order in the composition.
16934
    **/
16935
    _chart.shareColors = function (_) {
16936
        if (!arguments.length) {
16937
            return _shareColors;
16938
        }
16939
        _shareColors = _;
16940
        return _chart;
16941
    };
16942
16943
    /**
16944
    #### .shareTitle([[boolean])
16945
    Get or set title sharing for the chart. If set, the `.title()` value from this chart will be
16946
    shared with composed children. Default value is true.
16947
    **/
16948
    _chart.shareTitle = function (_) {
16949
        if (!arguments.length) {
16950
            return _shareTitle;
16951
        }
16952
        _shareTitle = _;
16953
        return _chart;
16954
    };
16955
16956
    /**
16957
    #### .rightY([yScale])
16958
    Get or set the y scale for the right axis. The right y scale is typically automatically
16959
    generated by the chart implementation.
16960
16961
    **/
16962
    _chart.rightY = function (_) {
16963
        if (!arguments.length) {
16964
            return _rightY;
16965
        }
16966
        _rightY = _;
16967
        return _chart;
16968
    };
16969
16970
    function leftYAxisChildren() {
16971
        return _children.filter(function (child) {
16972
            return !child.useRightYAxis();
16973
        });
16974
    }
16975
16976
    function rightYAxisChildren() {
16977
        return _children.filter(function (child) {
16978
            return child.useRightYAxis();
16979
        });
16980
    }
16981
16982
    function getYAxisMin(charts) {
16983
        return charts.map(function (c) {
16984
            return c.yAxisMin();
16985
        });
16986
    }
16987
16988
    delete _chart.yAxisMin;
16989
    function yAxisMin() {
16990
        return d3.min(getYAxisMin(leftYAxisChildren()));
16991
    }
16992
16993
    function rightYAxisMin() {
16994
        return d3.min(getYAxisMin(rightYAxisChildren()));
16995
    }
16996
16997
    function getYAxisMax(charts) {
16998
        return charts.map(function (c) {
16999
            return c.yAxisMax();
17000
        });
17001
    }
17002
17003
    delete _chart.yAxisMax;
17004
    function yAxisMax() {
17005
        return dc.utils.add(d3.max(getYAxisMax(leftYAxisChildren())), _chart.yAxisPadding());
17006
    }
17007
17008
    function rightYAxisMax() {
17009
        return dc.utils.add(d3.max(getYAxisMax(rightYAxisChildren())), _chart.yAxisPadding());
17010
    }
17011
17012
    function getAllXAxisMinFromChildCharts() {
17013
        return _children.map(function (c) {
17014
            return c.xAxisMin();
17015
        });
17016
    }
17017
17018
    dc.override(_chart, 'xAxisMin', function () {
17019
        return dc.utils.subtract(d3.min(getAllXAxisMinFromChildCharts()), _chart.xAxisPadding());
17020
    });
17021
17022
    function getAllXAxisMaxFromChildCharts() {
17023
        return _children.map(function (c) {
17024
            return c.xAxisMax();
17025
        });
17026
    }
17027
17028
    dc.override(_chart, 'xAxisMax', function () {
17029
        return dc.utils.add(d3.max(getAllXAxisMaxFromChildCharts()), _chart.xAxisPadding());
17030
    });
17031
17032
    _chart.legendables = function () {
17033
        return _children.reduce(function (items, child) {
17034
            if (_shareColors) {
17035
                child.colors(_chart.colors());
17036
            }
17037
            items.push.apply(items, child.legendables());
17038
            return items;
17039
        }, []);
17040
    };
17041
17042
    _chart.legendHighlight = function (d) {
17043
        for (var j = 0; j < _children.length; ++j) {
17044
            var child = _children[j];
17045
            child.legendHighlight(d);
17046
        }
17047
    };
17048
17049
    _chart.legendReset = function (d) {
17050
        for (var j = 0; j < _children.length; ++j) {
17051
            var child = _children[j];
17052
            child.legendReset(d);
17053
        }
17054
    };
17055
17056
    _chart.legendToggle = function () {
17057
        console.log('composite should not be getting legendToggle itself');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
17058
    };
17059
17060
    /**
17061
    #### .rightYAxis([yAxis])
17062
    Set or get the right y axis used by the composite chart. This function is most useful when y
17063
    axis customization is required. The y axis in dc.js is an instance of a [d3 axis
17064
    object](https://github.com/mbostock/d3/wiki/SVG-Axes#wiki-_axis) therefore it supports any valid
17065
    d3 axis manipulation. **Caution**: The y axis is usually generated internally by dc;
17066
    resetting it may cause unexpected results.
17067
    ```jså
17068
    // customize y axis tick format
17069
    chart.rightYAxis().tickFormat(function (v) {return v + '%';});
17070
    // customize y axis tick values
17071
    chart.rightYAxis().tickValues([0, 100, 200, 300]);
17072
    ```
17073
17074
    **/
17075
    _chart.rightYAxis = function (rightYAxis) {
17076
        if (!arguments.length) {
17077
            return _rightYAxis;
17078
        }
17079
        _rightYAxis = rightYAxis;
17080
        return _chart;
17081
    };
17082
17083
    return _chart.anchor(parent, chartGroup);
17084
};
17085
17086
/**
17087
 ## Series Chart
17088
17089
 Includes: [Composite Chart](#composite chart)
17090
17091
 A series chart is a chart that shows multiple series of data overlaid on one chart, where the
17092
 series is specified in the data. It is a specialization of Composite Chart and inherits all
17093
 composite features other than recomposing the chart.
17094
17095
 #### dc.seriesChart(parent[, chartGroup])
17096
 Create a series chart instance and attach it to the given parent element.
17097
17098
 Parameters:
17099
* parent : string | node | selection - any valid
17100
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
17101
 a dom block element such as a div; or a dom element or d3 selection.
17102
17103
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
17104
 Interaction with a chart will only trigger events and redraws within the chart's group.
17105
17106
 Returns:
17107
 A newly created series chart instance
17108
17109
 ```js
17110
 // create a series chart under #chart-container1 element using the default global chart group
17111
 var seriesChart1 = dc.seriesChart("#chart-container1");
17112
 // create a series chart under #chart-container2 element using chart group A
17113
 var seriesChart2 = dc.seriesChart("#chart-container2", "chartGroupA");
17114
 ```
17115
17116
 **/
17117
dc.seriesChart = function (parent, chartGroup) {
17118
    var _chart = dc.compositeChart(parent, chartGroup);
17119
17120
    function keySort(a, b) {
17121
        return d3.ascending(_chart.keyAccessor()(a), _chart.keyAccessor()(b));
17122
    }
17123
17124
    var _charts = {};
17125
    var _chartFunction = dc.lineChart;
17126
    var _seriesAccessor;
17127
    var _seriesSort = d3.ascending;
17128
    var _valueSort = keySort;
17129
17130
    _chart._mandatoryAttributes().push('seriesAccessor', 'chart');
17131
    _chart.shareColors(true);
17132
17133
    _chart._preprocessData = function () {
17134
        var keep = [];
17135
        var childrenChanged;
17136
        var nester = d3.nest().key(_seriesAccessor);
17137
        if (_seriesSort) {
17138
            nester.sortKeys(_seriesSort);
17139
        }
17140
        if (_valueSort) {
17141
            nester.sortValues(_valueSort);
17142
        }
17143
        var nesting = nester.entries(_chart.data());
17144
        var children =
17145
            nesting.map(function (sub, i) {
17146
                var subChart = _charts[sub.key] || _chartFunction.call(_chart, _chart, chartGroup, sub.key, i);
17147
                if (!_charts[sub.key]) {
17148
                    childrenChanged = true;
17149
                }
17150
                _charts[sub.key] = subChart;
17151
                keep.push(sub.key);
17152
                return subChart
17153
                    .dimension(_chart.dimension())
17154
                    .group({all:d3.functor(sub.values)}, sub.key)
17155
                    .keyAccessor(_chart.keyAccessor())
17156
                    .valueAccessor(_chart.valueAccessor())
17157
                    .brushOn(_chart.brushOn());
17158
            });
17159
        // this works around the fact compositeChart doesn't really
17160
        // have a removal interface
17161
        Object.keys(_charts)
17162
            .filter(function (c) {return keep.indexOf(c) === -1;})
17163
            .forEach(function (c) {
17164
                clearChart(c);
17165
                childrenChanged = true;
17166
            });
17167
        _chart._compose(children);
17168
        if (childrenChanged && _chart.legend()) {
17169
            _chart.legend().render();
17170
        }
17171
    };
17172
17173
    function clearChart(c) {
17174
        if (_charts[c].g()) {
17175
            _charts[c].g().remove();
17176
        }
17177
        delete _charts[c];
17178
    }
17179
17180
    function resetChildren() {
17181
        Object.keys(_charts).map(clearChart);
17182
        _charts = {};
17183
    }
17184
17185
    /**
17186
     #### .chart([function])
17187
     Get or set the chart function, which generates the child charts.  Default: dc.lineChart
17188
17189
     ```
17190
     // put interpolation on the line charts used for the series
17191
     chart.chart(function(c) { return dc.lineChart(c).interpolate('basis'); })
17192
     // do a scatter series chart
17193
     chart.chart(dc.scatterPlot)
17194
     ```
17195
17196
     **/
17197
    _chart.chart = function (_) {
17198
        if (!arguments.length) {
17199
            return _chartFunction;
17200
        }
17201
        _chartFunction = _;
17202
        resetChildren();
17203
        return _chart;
17204
    };
17205
17206
    /**
17207
     #### .seriesAccessor([accessor])
17208
     Get or set accessor function for the displayed series. Given a datum, this function
17209
     should return the series that datum belongs to.
17210
     **/
17211
    _chart.seriesAccessor = function (_) {
17212
        if (!arguments.length) {
17213
            return _seriesAccessor;
17214
        }
17215
        _seriesAccessor = _;
17216
        resetChildren();
17217
        return _chart;
17218
    };
17219
17220
    /**
17221
     #### .seriesSort([sortFunction])
17222
     Get or set a function to sort the list of series by, given series values.
17223
17224
     Example:
17225
     ```
17226
     chart.seriesSort(d3.descending);
17227
     ```
17228
     **/
17229
    _chart.seriesSort = function (_) {
17230
        if (!arguments.length) {
17231
            return _seriesSort;
17232
        }
17233
        _seriesSort = _;
17234
        resetChildren();
17235
        return _chart;
17236
    };
17237
17238
    /**
17239
     #### .valueSort([sortFunction])
17240
     Get or set a function to sort each series values by. By default this is the key accessor which,
17241
     for example, will ensure a lineChart series connects its points in increasing key/x order,
17242
     rather than haphazardly.
17243
    **/
17244
    _chart.valueSort = function (_) {
17245
        if (!arguments.length) {
17246
            return _valueSort;
17247
        }
17248
        _valueSort = _;
17249
        resetChildren();
17250
        return _chart;
17251
    };
17252
17253
    // make compose private
17254
    _chart._compose = _chart.compose;
17255
    delete _chart.compose;
17256
17257
    return _chart;
17258
};
17259
17260
/**
17261
## Geo Choropleth Chart
17262
Includes: [Color Mixin](#color-mixin), [Base Mixin](#base-mixin)
17263
17264
The geo choropleth chart is designed as an easy way to create a crossfilter driven choropleth map
17265
from GeoJson data. This chart implementation was inspired by [the great d3 choropleth
17266
example](http://bl.ocks.org/4060606).
17267
17268
Examples:
17269
* [US Venture Capital Landscape 2011](http://dc-js.github.com/dc.js/vc/index.html)
17270
#### dc.geoChoroplethChart(parent[, chartGroup])
17271
Create a choropleth chart instance and attach it to the given parent element.
17272
17273
Parameters:
17274
* parent : string | node | selection - any valid
17275
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
17276
 a dom block element such as a div; or a dom element or d3 selection.
17277
17278
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
17279
 Interaction with a chart will only trigger events and redraws within the chart's group.
17280
17281
Returns:
17282
A newly created choropleth chart instance
17283
17284
```js
17285
// create a choropleth chart under '#us-chart' element using the default global chart group
17286
var chart1 = dc.geoChoroplethChart('#us-chart');
17287
// create a choropleth chart under '#us-chart2' element using chart group A
17288
var chart2 = dc.compositeChart('#us-chart2', 'chartGroupA');
17289
```
17290
17291
**/
17292
dc.geoChoroplethChart = function (parent, chartGroup) {
17293
    var _chart = dc.colorMixin(dc.baseMixin({}));
17294
17295
    _chart.colorAccessor(function (d) {
17296
        return d || 0;
17297
    });
17298
17299
    var _geoPath = d3.geo.path();
17300
    var _projectionFlag;
17301
17302
    var _geoJsons = [];
17303
17304
    _chart._doRender = function () {
17305
        _chart.resetSvg();
17306
        for (var layerIndex = 0; layerIndex < _geoJsons.length; ++layerIndex) {
17307
            var states = _chart.svg().append('g')
17308
                .attr('class', 'layer' + layerIndex);
17309
17310
            var regionG = states.selectAll('g.' + geoJson(layerIndex).name)
17311
                .data(geoJson(layerIndex).data)
17312
                .enter()
17313
                .append('g')
17314
                .attr('class', geoJson(layerIndex).name);
17315
17316
            regionG
17317
                .append('path')
17318
                .attr('fill', 'white')
17319
                .attr('d', _geoPath);
17320
17321
            regionG.append('title');
17322
17323
            plotData(layerIndex);
17324
        }
17325
        _projectionFlag = false;
17326
    };
17327
17328
    function plotData(layerIndex) {
17329
        var data = generateLayeredData();
17330
17331
        if (isDataLayer(layerIndex)) {
17332
            var regionG = renderRegionG(layerIndex);
17333
17334
            renderPaths(regionG, layerIndex, data);
17335
17336
            renderTitle(regionG, layerIndex, data);
17337
        }
17338
    }
17339
17340
    function generateLayeredData() {
17341
        var data = {};
17342
        var groupAll = _chart.data();
17343
        for (var i = 0; i < groupAll.length; ++i) {
17344
            data[_chart.keyAccessor()(groupAll[i])] = _chart.valueAccessor()(groupAll[i]);
17345
        }
17346
        return data;
17347
    }
17348
17349
    function isDataLayer(layerIndex) {
17350
        return geoJson(layerIndex).keyAccessor;
17351
    }
17352
17353
    function renderRegionG(layerIndex) {
17354
        var regionG = _chart.svg()
17355
            .selectAll(layerSelector(layerIndex))
17356
            .classed('selected', function (d) {
17357
                return isSelected(layerIndex, d);
17358
            })
17359
            .classed('deselected', function (d) {
17360
                return isDeselected(layerIndex, d);
17361
            })
17362
            .attr('class', function (d) {
17363
                var layerNameClass = geoJson(layerIndex).name;
17364
                var regionClass = dc.utils.nameToId(geoJson(layerIndex).keyAccessor(d));
17365
                var baseClasses = layerNameClass + ' ' + regionClass;
17366
                if (isSelected(layerIndex, d)) {
17367
                    baseClasses += ' selected';
17368
                }
17369
                if (isDeselected(layerIndex, d)) {
17370
                    baseClasses += ' deselected';
17371
                }
17372
                return baseClasses;
17373
            });
17374
        return regionG;
17375
    }
17376
17377
    function layerSelector(layerIndex) {
17378
        return 'g.layer' + layerIndex + ' g.' + geoJson(layerIndex).name;
17379
    }
17380
17381
    function isSelected(layerIndex, d) {
17382
        return _chart.hasFilter() && _chart.hasFilter(getKey(layerIndex, d));
17383
    }
17384
17385
    function isDeselected(layerIndex, d) {
17386
        return _chart.hasFilter() && !_chart.hasFilter(getKey(layerIndex, d));
17387
    }
17388
17389
    function getKey(layerIndex, d) {
17390
        return geoJson(layerIndex).keyAccessor(d);
17391
    }
17392
17393
    function geoJson(index) {
17394
        return _geoJsons[index];
17395
    }
17396
17397
    function renderPaths(regionG, layerIndex, data) {
17398
        var paths = regionG
17399
            .select('path')
17400
            .attr('fill', function () {
17401
                var currentFill = d3.select(this).attr('fill');
17402
                if (currentFill) {
17403
                    return currentFill;
17404
                }
17405
                return 'none';
17406
            })
17407
            .on('click', function (d) {
17408
                return _chart.onClick(d, layerIndex);
17409
            });
17410
17411
        dc.transition(paths, _chart.transitionDuration()).attr('fill', function (d, i) {
17412
            return _chart.getColor(data[geoJson(layerIndex).keyAccessor(d)], i);
17413
        });
17414
    }
17415
17416
    _chart.onClick = function (d, layerIndex) {
17417
        var selectedRegion = geoJson(layerIndex).keyAccessor(d);
17418
        dc.events.trigger(function () {
17419
            _chart.filter(selectedRegion);
17420
            _chart.redrawGroup();
17421
        });
17422
    };
17423
17424
    function renderTitle(regionG, layerIndex, data) {
17425
        if (_chart.renderTitle()) {
17426
            regionG.selectAll('title').text(function (d) {
17427
                var key = getKey(layerIndex, d);
17428
                var value = data[key];
17429
                return _chart.title()({key: key, value: value});
17430
            });
17431
        }
17432
    }
17433
17434
    _chart._doRedraw = function () {
17435
        for (var layerIndex = 0; layerIndex < _geoJsons.length; ++layerIndex) {
17436
            plotData(layerIndex);
17437
            if (_projectionFlag) {
17438
                _chart.svg().selectAll('g.' + geoJson(layerIndex).name + ' path').attr('d', _geoPath);
17439
            }
17440
        }
17441
        _projectionFlag = false;
17442
    };
17443
17444
    /**
17445
    #### .overlayGeoJson(json, name, keyAccessor) - **mandatory**
17446
    Use this function to insert a new GeoJson map layer. This function can be invoked multiple times
17447
    if you have multiple GeoJson data layers to render on top of each other. If you overlay multiple
17448
    layers with the same name the new overlay will override the existing one.
17449
17450
    Parameters:
17451
    * json - GeoJson feed
17452
    * name - name of the layer
17453
    * keyAccessor - accessor function used to extract 'key' from the GeoJson data. The key extracted by
17454
    this function should match the keys returned by the crossfilter groups.
17455
17456
    ```js
17457
    // insert a layer for rendering US states
17458
    chart.overlayGeoJson(statesJson.features, 'state', function(d) {
17459
        return d.properties.name;
17460
    });
17461
    ```
17462
17463
    **/
17464
    _chart.overlayGeoJson = function (json, name, keyAccessor) {
17465
        for (var i = 0; i < _geoJsons.length; ++i) {
17466
            if (_geoJsons[i].name === name) {
17467
                _geoJsons[i].data = json;
17468
                _geoJsons[i].keyAccessor = keyAccessor;
17469
                return _chart;
17470
            }
17471
        }
17472
        _geoJsons.push({name: name, data: json, keyAccessor: keyAccessor});
17473
        return _chart;
17474
    };
17475
17476
    /**
17477
    #### .projection(projection)
17478
    Set custom geo projection function. See the available [d3 geo projection
17479
    functions](https://github.com/mbostock/d3/wiki/Geo-Projections).  Default value: albersUsa.
17480
17481
    **/
17482
    _chart.projection = function (projection) {
17483
        _geoPath.projection(projection);
17484
        _projectionFlag = true;
17485
        return _chart;
17486
    };
17487
17488
    /**
17489
    #### .geoJsons()
17490
    Returns all GeoJson layers currently registered with this chart. The returned array is a
17491
    reference to this chart's internal data structure, so any modification to this array will also
17492
    modify this chart's internal registration.
17493
17494
    Returns an array of objects containing fields {name, data, accessor}
17495
17496
    **/
17497
    _chart.geoJsons = function () {
17498
        return _geoJsons;
17499
    };
17500
17501
    /**
17502
    #### .geoPath()
17503
    Returns the [d3.geo.path](https://github.com/mbostock/d3/wiki/Geo-Paths#path) object used to
17504
    render the projection and features.  Can be useful for figuring out the bounding box of the
17505
    feature set and thus a way to calculate scale and translation for the projection.
17506
17507
    **/
17508
    _chart.geoPath = function () {
17509
        return _geoPath;
17510
    };
17511
17512
    /**
17513
    #### .removeGeoJson(name)
17514
    Remove a GeoJson layer from this chart by name
17515
17516
    **/
17517
    _chart.removeGeoJson = function (name) {
17518
        var geoJsons = [];
17519
17520
        for (var i = 0; i < _geoJsons.length; ++i) {
17521
            var layer = _geoJsons[i];
17522
            if (layer.name !== name) {
17523
                geoJsons.push(layer);
17524
            }
17525
        }
17526
17527
        _geoJsons = geoJsons;
17528
17529
        return _chart;
17530
    };
17531
17532
    return _chart.anchor(parent, chartGroup);
17533
};
17534
17535
/**
17536
## Bubble Overlay Chart
17537
Includes: [Bubble Mixin](#bubble-mixin), [Base Mixin](#base-mixin)
17538
17539
The bubble overlay chart is quite different from the typical bubble chart. With the bubble overlay
17540
chart you can arbitrarily place bubbles on an existing svg or bitmap image, thus changing the
17541
typical x and y positioning while retaining the capability to visualize data using bubble radius
17542
and coloring.
17543
17544
Examples:
17545
* [Canadian City Crime Stats](http://dc-js.github.com/dc.js/crime/index.html)
17546
#### dc.bubbleOverlay(parent[, chartGroup])
17547
Create a bubble overlay chart instance and attach it to the given parent element.
17548
17549
Parameters:
17550
* parent : string | node | selection - any valid
17551
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
17552
 a dom block element such as a div; or a dom element or d3 selection.
17553
 off-screen. Typically this element should also be the parent of the underlying image.
17554
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
17555
 Interaction with a chart will only trigger events and redraws within the chart's group.
17556
17557
Returns:
17558
A newly created bubble overlay chart instance
17559
17560
```js
17561
// create a bubble overlay chart on top of the '#chart-container1 svg' element using the default global chart group
17562
var bubbleChart1 = dc.bubbleOverlayChart('#chart-container1').svg(d3.select('#chart-container1 svg'));
17563
// create a bubble overlay chart on top of the '#chart-container2 svg' element using chart group A
17564
var bubbleChart2 = dc.compositeChart('#chart-container2', 'chartGroupA').svg(d3.select('#chart-container2 svg'));
17565
```
17566
#### .svg(imageElement) - **mandatory**
17567
Set the underlying svg image element. Unlike other dc charts this chart will not generate a svg
17568
element; therefore the bubble overlay chart will not work if this function is not invoked. If the
17569
underlying image is a bitmap, then an empty svg will need to be created on top of the image.
17570
17571
```js
17572
// set up underlying svg element
17573
chart.svg(d3.select('#chart svg'));
17574
```
17575
17576
**/
17577
dc.bubbleOverlay = function (root, chartGroup) {
17578
    var BUBBLE_OVERLAY_CLASS = 'bubble-overlay';
17579
    var BUBBLE_NODE_CLASS = 'node';
17580
    var BUBBLE_CLASS = 'bubble';
17581
17582
    var _chart = dc.bubbleMixin(dc.baseMixin({}));
17583
    var _g;
17584
    var _points = [];
17585
17586
    _chart.transitionDuration(750);
17587
17588
    _chart.radiusValueAccessor(function (d) {
17589
        return d.value;
17590
    });
17591
17592
    /**
17593
    #### .point(name, x, y) - **mandatory**
17594
    Set up a data point on the overlay. The name of a data point should match a specific 'key' among
17595
    data groups generated using keyAccessor.  If a match is found (point name <-> data group key)
17596
    then a bubble will be generated at the position specified by the function. x and y
17597
    value specified here are relative to the underlying svg.
17598
17599
    **/
17600
    _chart.point = function (name, x, y) {
17601
        _points.push({name: name, x: x, y: y});
17602
        return _chart;
17603
    };
17604
17605
    _chart._doRender = function () {
17606
        _g = initOverlayG();
17607
17608
        _chart.r().range([_chart.MIN_RADIUS, _chart.width() * _chart.maxBubbleRelativeSize()]);
17609
17610
        initializeBubbles();
17611
17612
        _chart.fadeDeselectedArea();
17613
17614
        return _chart;
17615
    };
17616
17617
    function initOverlayG() {
17618
        _g = _chart.select('g.' + BUBBLE_OVERLAY_CLASS);
17619
        if (_g.empty()) {
17620
            _g = _chart.svg().append('g').attr('class', BUBBLE_OVERLAY_CLASS);
17621
        }
17622
        return _g;
17623
    }
17624
17625
    function initializeBubbles() {
17626
        var data = mapData();
17627
17628
        _points.forEach(function (point) {
17629
            var nodeG = getNodeG(point, data);
17630
17631
            var circle = nodeG.select('circle.' + BUBBLE_CLASS);
17632
17633
            if (circle.empty()) {
17634
                circle = nodeG.append('circle')
17635
                    .attr('class', BUBBLE_CLASS)
17636
                    .attr('r', 0)
17637
                    .attr('fill', _chart.getColor)
17638
                    .on('click', _chart.onClick);
17639
            }
17640
17641
            dc.transition(circle, _chart.transitionDuration())
17642
                .attr('r', function (d) {
17643
                    return _chart.bubbleR(d);
17644
                });
17645
17646
            _chart._doRenderLabel(nodeG);
17647
17648
            _chart._doRenderTitles(nodeG);
17649
        });
17650
    }
17651
17652
    function mapData() {
17653
        var data = {};
17654
        _chart.data().forEach(function (datum) {
17655
            data[_chart.keyAccessor()(datum)] = datum;
17656
        });
17657
        return data;
17658
    }
17659
17660
    function getNodeG(point, data) {
17661
        var bubbleNodeClass = BUBBLE_NODE_CLASS + ' ' + dc.utils.nameToId(point.name);
17662
17663
        var nodeG = _g.select('g.' + dc.utils.nameToId(point.name));
17664
17665
        if (nodeG.empty()) {
17666
            nodeG = _g.append('g')
17667
                .attr('class', bubbleNodeClass)
17668
                .attr('transform', 'translate(' + point.x + ',' + point.y + ')');
17669
        }
17670
17671
        nodeG.datum(data[point.name]);
17672
17673
        return nodeG;
17674
    }
17675
17676
    _chart._doRedraw = function () {
17677
        updateBubbles();
17678
17679
        _chart.fadeDeselectedArea();
17680
17681
        return _chart;
17682
    };
17683
17684
    function updateBubbles() {
17685
        var data = mapData();
17686
17687
        _points.forEach(function (point) {
17688
            var nodeG = getNodeG(point, data);
17689
17690
            var circle = nodeG.select('circle.' + BUBBLE_CLASS);
17691
17692
            dc.transition(circle, _chart.transitionDuration())
17693
                .attr('r', function (d) {
17694
                    return _chart.bubbleR(d);
17695
                })
17696
                .attr('fill', _chart.getColor);
17697
17698
            _chart.doUpdateLabels(nodeG);
17699
17700
            _chart.doUpdateTitles(nodeG);
17701
        });
17702
    }
17703
17704
    _chart.debug = function (flag) {
17705
        if (flag) {
17706
            var debugG = _chart.select('g.' + dc.constants.DEBUG_GROUP_CLASS);
17707
17708
            if (debugG.empty()) {
17709
                debugG = _chart.svg()
17710
                    .append('g')
17711
                    .attr('class', dc.constants.DEBUG_GROUP_CLASS);
17712
            }
17713
17714
            var debugText = debugG.append('text')
17715
                .attr('x', 10)
17716
                .attr('y', 20);
17717
17718
            debugG
17719
                .append('rect')
17720
                .attr('width', _chart.width())
17721
                .attr('height', _chart.height())
17722
                .on('mousemove', function () {
17723
                    var position = d3.mouse(debugG.node());
17724
                    var msg = position[0] + ', ' + position[1];
17725
                    debugText.text(msg);
17726
                });
17727
        } else {
17728
            _chart.selectAll('.debug').remove();
17729
        }
17730
17731
        return _chart;
17732
    };
17733
17734
    _chart.anchor(root, chartGroup);
17735
17736
    return _chart;
17737
};
17738
17739
/**
17740
## Row Chart
17741
Includes: [Cap Mixin](#cap-mixin), [Margin Mixin](#margin-mixin), [Color Mixin](#color-mixin), [Base Mixin](#base-mixin)
17742
17743
Concrete row chart implementation.
17744
#### dc.rowChart(parent[, chartGroup])
17745
Create a row chart instance and attach it to the given parent element.
17746
17747
Parameters:
17748
17749
* parent : string | node | selection - any valid
17750
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
17751
 a dom block element such as a div; or a dom element or d3 selection.
17752
17753
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
17754
 Interaction with a chart will only trigger events and redraws within the chart's group.
17755
17756
Returns:
17757
A newly created row chart instance
17758
17759
```js
17760
// create a row chart under #chart-container1 element using the default global chart group
17761
var chart1 = dc.rowChart('#chart-container1');
17762
// create a row chart under #chart-container2 element using chart group A
17763
var chart2 = dc.rowChart('#chart-container2', 'chartGroupA');
17764
```
17765
17766
**/
17767
dc.rowChart = function (parent, chartGroup) {
17768
17769
    var _g;
17770
17771
    var _labelOffsetX = 10;
17772
    var _labelOffsetY = 15;
17773
    var _hasLabelOffsetY = false;
17774
    var _dyOffset = '0.35em';  // this helps center labels https://github.com/mbostock/d3/wiki/SVG-Shapes#svg_text
17775
    var _titleLabelOffsetX = 2;
17776
17777
    var _gap = 5;
17778
17779
    var _fixedBarHeight = false;
17780
    var _rowCssClass = 'row';
17781
    var _titleRowCssClass = 'titlerow';
17782
    var _renderTitleLabel = false;
17783
17784
    var _chart = dc.capMixin(dc.marginMixin(dc.colorMixin(dc.baseMixin({}))));
17785
17786
    var _x;
17787
17788
    var _elasticX;
17789
17790
    var _xAxis = d3.svg.axis().orient('bottom');
17791
17792
    var _rowData;
17793
17794
    _chart.rowsCap = _chart.cap;
17795
17796
    function calculateAxisScale() {
17797
        if (!_x || _elasticX) {
17798
            var extent = d3.extent(_rowData, _chart.cappedValueAccessor);
17799
            if (extent[0] > 0) {
17800
                extent[0] = 0;
17801
            }
17802
            _x = d3.scale.linear().domain(extent)
17803
                .range([0, _chart.effectiveWidth()]);
17804
        }
17805
        _xAxis.scale(_x);
17806
    }
17807
17808
    function drawAxis() {
17809
        var axisG = _g.select('g.axis');
17810
17811
        calculateAxisScale();
17812
17813
        if (axisG.empty()) {
17814
            axisG = _g.append('g').attr('class', 'axis')
17815
                .attr('transform', 'translate(0, ' + _chart.effectiveHeight() + ')');
17816
        }
17817
17818
        dc.transition(axisG, _chart.transitionDuration())
17819
            .call(_xAxis);
17820
    }
17821
17822
    _chart._doRender = function () {
17823
        _chart.resetSvg();
17824
17825
        _g = _chart.svg()
17826
            .append('g')
17827
            .attr('transform', 'translate(' + _chart.margins().left + ',' + _chart.margins().top + ')');
17828
17829
        drawChart();
17830
17831
        return _chart;
17832
    };
17833
17834
    _chart.title(function (d) {
17835
        return _chart.cappedKeyAccessor(d) + ': ' + _chart.cappedValueAccessor(d);
17836
    });
17837
17838
    _chart.label(_chart.cappedKeyAccessor);
17839
17840
    /**
17841
     #### .x([scale])
17842
     Gets or sets the x scale. The x scale can be any d3
17843
     [quantitive scale](https://github.com/mbostock/d3/wiki/Quantitative-Scales)
17844
     **/
17845
    _chart.x = function (x) {
17846
        if (!arguments.length) {
17847
            return _x;
17848
        }
17849
        _x = x;
17850
        return _chart;
17851
    };
17852
17853
    function drawGridLines() {
17854
        _g.selectAll('g.tick')
17855
            .select('line.grid-line')
17856
            .remove();
17857
17858
        _g.selectAll('g.tick')
17859
            .append('line')
17860
            .attr('class', 'grid-line')
17861
            .attr('x1', 0)
17862
            .attr('y1', 0)
17863
            .attr('x2', 0)
17864
            .attr('y2', function () {
17865
                return -_chart.effectiveHeight();
17866
            });
17867
    }
17868
17869
    function drawChart() {
17870
        _rowData = _chart.data();
17871
17872
        drawAxis();
17873
        drawGridLines();
17874
17875
        var rows = _g.selectAll('g.' + _rowCssClass)
17876
            .data(_rowData);
17877
17878
        createElements(rows);
17879
        removeElements(rows);
17880
        updateElements(rows);
17881
    }
17882
17883
    function createElements(rows) {
17884
        var rowEnter = rows.enter()
17885
            .append('g')
17886
            .attr('class', function (d, i) {
17887
                return _rowCssClass + ' _' + i;
17888
            });
17889
17890
        rowEnter.append('rect').attr('width', 0);
17891
17892
        createLabels(rowEnter);
17893
        updateLabels(rows);
17894
    }
17895
17896
    function removeElements(rows) {
17897
        rows.exit().remove();
17898
    }
17899
17900
    function rootValue() {
17901
        var root = _x(0);
17902
        return (root === -Infinity || root !== root) ? _x(1) : root;
17903
    }
17904
17905
    function updateElements(rows) {
17906
        var n = _rowData.length;
17907
17908
        var height;
17909
        if (!_fixedBarHeight) {
17910
            height = (_chart.effectiveHeight() - (n + 1) * _gap) / n;
17911
        } else {
17912
            height = _fixedBarHeight;
17913
        }
17914
17915
        // vertically align label in center unless they override the value via property setter
17916
        if (!_hasLabelOffsetY) {
17917
            _labelOffsetY = height / 2;
17918
        }
17919
17920
        var rect = rows.attr('transform', function (d, i) {
17921
                return 'translate(0,' + ((i + 1) * _gap + i * height) + ')';
17922
            }).select('rect')
17923
            .attr('height', height)
17924
            .attr('fill', _chart.getColor)
17925
            .on('click', onClick)
17926
            .classed('deselected', function (d) {
17927
                return (_chart.hasFilter()) ? !isSelectedRow(d) : false;
17928
            })
17929
            .classed('selected', function (d) {
17930
                return (_chart.hasFilter()) ? isSelectedRow(d) : false;
17931
            });
17932
17933
        dc.transition(rect, _chart.transitionDuration())
17934
            .attr('width', function (d) {
17935
                return Math.abs(rootValue() - _x(_chart.valueAccessor()(d)));
17936
            })
17937
            .attr('transform', translateX);
17938
17939
        createTitles(rows);
17940
        updateLabels(rows);
17941
    }
17942
17943
    function createTitles(rows) {
17944
        if (_chart.renderTitle()) {
17945
            rows.selectAll('title').remove();
17946
            rows.append('title').text(_chart.title());
17947
        }
17948
    }
17949
17950
    function createLabels(rowEnter) {
17951
        if (_chart.renderLabel()) {
17952
            rowEnter.append('text')
17953
                .on('click', onClick);
17954
        }
17955
        if (_chart.renderTitleLabel()) {
17956
            rowEnter.append('text')
17957
                .attr('class', _titleRowCssClass)
17958
                .on('click', onClick);
17959
        }
17960
    }
17961
17962
    function updateLabels(rows) {
17963
        if (_chart.renderLabel()) {
17964
            var lab = rows.select('text')
17965
                .attr('x', _labelOffsetX)
17966
                .attr('y', _labelOffsetY)
17967
                .attr('dy', _dyOffset)
17968
                .on('click', onClick)
17969
                .attr('class', function (d, i) {
17970
                    return _rowCssClass + ' _' + i;
17971
                })
17972
                .text(function (d) {
17973
                    return _chart.label()(d);
17974
                });
17975
            dc.transition(lab, _chart.transitionDuration())
17976
                .attr('transform', translateX);
17977
        }
17978
        if (_chart.renderTitleLabel()) {
17979
            var titlelab = rows.select('.' + _titleRowCssClass)
17980
                    .attr('x', _chart.effectiveWidth() - _titleLabelOffsetX)
17981
                    .attr('y', _labelOffsetY)
17982
                    .attr('text-anchor', 'end')
17983
                    .on('click', onClick)
17984
                    .attr('class', function (d, i) {
17985
                        return _titleRowCssClass + ' _' + i ;
17986
                    })
17987
                    .text(function (d) {
17988
                        return _chart.title()(d);
17989
                    });
17990
            dc.transition(titlelab, _chart.transitionDuration())
17991
                .attr('transform', translateX);
17992
        }
17993
    }
17994
17995
    /**
17996
    #### .renderTitleLabel(boolean)
17997
    Turn on/off Title label rendering (values) using SVG style of text-anchor 'end'
17998
17999
    **/
18000
    _chart.renderTitleLabel = function (_) {
18001
        if (!arguments.length) {
18002
            return _renderTitleLabel;
18003
        }
18004
        _renderTitleLabel = _;
18005
        return _chart;
18006
    };
18007
18008
    function onClick(d) {
18009
        _chart.onClick(d);
18010
    }
18011
18012
    function translateX(d) {
18013
        var x = _x(_chart.cappedValueAccessor(d)),
18014
            x0 = rootValue(),
18015
            s = x > x0 ? x0 : x;
18016
        return 'translate(' + s + ',0)';
18017
    }
18018
18019
    _chart._doRedraw = function () {
18020
        drawChart();
18021
        return _chart;
18022
    };
18023
18024
    /**
18025
    #### .xAxis()
18026
    Get the x axis for the row chart instance.  Note: not settable for row charts.
18027
    See the [d3 axis object](https://github.com/mbostock/d3/wiki/SVG-Axes#wiki-axis) documention for more information.
18028
    ```js
18029
    // customize x axis tick format
18030
    chart.xAxis().tickFormat(function (v) {return v + '%';});
18031
    // customize x axis tick values
18032
    chart.xAxis().tickValues([0, 100, 200, 300]);
18033
    ```
18034
18035
    **/
18036
    _chart.xAxis = function () {
18037
        return _xAxis;
18038
    };
18039
18040
    /**
18041
    #### .fixedBarHeight([height])
18042
    Get or set the fixed bar height. Default is [false] which will auto-scale bars.
18043
    For example, if you want to fix the height for a specific number of bars (useful in TopN charts)
18044
    you could fix height as follows (where count = total number of bars in your TopN and gap is
18045
    your vertical gap space).
18046
    ```js
18047
     chart.fixedBarHeight( chartheight - (count + 1) * gap / count);
18048
    ```
18049
    **/
18050
    _chart.fixedBarHeight = function (g) {
18051
        if (!arguments.length) {
18052
            return _fixedBarHeight;
18053
        }
18054
        _fixedBarHeight = g;
18055
        return _chart;
18056
    };
18057
18058
    /**
18059
    #### .gap([gap])
18060
    Get or set the vertical gap space between rows on a particular row chart instance. Default gap is 5px;
18061
18062
    **/
18063
    _chart.gap = function (g) {
18064
        if (!arguments.length) {
18065
            return _gap;
18066
        }
18067
        _gap = g;
18068
        return _chart;
18069
    };
18070
18071
    /**
18072
    #### .elasticX([boolean])
18073
    Get or set the elasticity on x axis. If this attribute is set to true, then the x axis will rescle to auto-fit the
18074
    data range when filtered.
18075
18076
    **/
18077
    _chart.elasticX = function (_) {
18078
        if (!arguments.length) {
18079
            return _elasticX;
18080
        }
18081
        _elasticX = _;
18082
        return _chart;
18083
    };
18084
18085
    /**
18086
    #### .labelOffsetX([x])
18087
    Get or set the x offset (horizontal space to the top left corner of a row) for labels on a particular row chart.
18088
    Default x offset is 10px;
18089
18090
    **/
18091
    _chart.labelOffsetX = function (o) {
18092
        if (!arguments.length) {
18093
            return _labelOffsetX;
18094
        }
18095
        _labelOffsetX = o;
18096
        return _chart;
18097
    };
18098
18099
    /**
18100
    #### .labelOffsetY([y])
18101
    Get or set the y offset (vertical space to the top left corner of a row) for labels on a particular row chart.
18102
    Default y offset is 15px;
18103
18104
    **/
18105
    _chart.labelOffsetY = function (o) {
18106
        if (!arguments.length) {
18107
            return _labelOffsetY;
18108
        }
18109
        _labelOffsetY = o;
18110
        _hasLabelOffsetY = true;
18111
        return _chart;
18112
    };
18113
18114
    /**
18115
    #### .titleLabelOffsetx([x])
18116
    Get of set the x offset (horizontal space between right edge of row and right edge or text.
18117
    Default x offset is 2px;
18118
18119
    **/
18120
    _chart.titleLabelOffsetX = function (o) {
18121
        if (!arguments.length) {
18122
            return _titleLabelOffsetX;
18123
        }
18124
        _titleLabelOffsetX = o;
18125
        return _chart;
18126
    };
18127
18128
    function isSelectedRow (d) {
18129
        return _chart.hasFilter(_chart.cappedKeyAccessor(d));
18130
    }
18131
18132
    return _chart.anchor(parent, chartGroup);
18133
};
18134
18135
/**
18136
## Legend
18137
Legend is a attachable widget that can be added to other dc charts to render horizontal legend
18138
labels.
18139
18140
```js
18141
chart.legend(dc.legend().x(400).y(10).itemHeight(13).gap(5))
18142
```
18143
18144
Examples:
18145
* [Nasdaq 100 Index](http://dc-js.github.com/dc.js/)
18146
* [Canadian City Crime Stats](http://dc-js.github.com/dc.js/crime/index.html)
18147
18148
**/
18149
dc.legend = function () {
18150
    var LABEL_GAP = 2;
18151
18152
    var _legend = {},
18153
        _parent,
18154
        _x = 0,
18155
        _y = 0,
18156
        _itemHeight = 12,
18157
        _gap = 5,
18158
        _horizontal = false,
18159
        _legendWidth = 560,
18160
        _itemWidth = 70,
18161
        _autoItemWidth = false;
18162
18163
    var _g;
18164
18165
    _legend.parent = function (p) {
18166
        if (!arguments.length) {
18167
            return _parent;
18168
        }
18169
        _parent = p;
18170
        return _legend;
18171
    };
18172
18173
    _legend.render = function () {
18174
        _parent.svg().select('g.dc-legend').remove();
18175
        _g = _parent.svg().append('g')
18176
            .attr('class', 'dc-legend')
18177
            .attr('transform', 'translate(' + _x + ',' + _y + ')');
18178
        var legendables = _parent.legendables();
18179
18180
        var itemEnter = _g.selectAll('g.dc-legend-item')
18181
            .data(legendables)
18182
            .enter()
18183
            .append('g')
18184
            .attr('class', 'dc-legend-item')
18185
            .on('mouseover', function (d) {
18186
                _parent.legendHighlight(d);
18187
            })
18188
            .on('mouseout', function (d) {
18189
                _parent.legendReset(d);
18190
            })
18191
            .on('click', function (d) {
18192
                d.chart.legendToggle(d);
18193
            });
18194
18195
        _g.selectAll('g.dc-legend-item')
18196
            .classed('fadeout', function (d) {
18197
                return d.chart.isLegendableHidden(d);
18198
            });
18199
18200
        if (legendables.some(dc.pluck('dashstyle'))) {
18201
            itemEnter
18202
                .append('line')
18203
                .attr('x1', 0)
18204
                .attr('y1', _itemHeight / 2)
18205
                .attr('x2', _itemHeight)
18206
                .attr('y2', _itemHeight / 2)
18207
                .attr('stroke-width', 2)
18208
                .attr('stroke-dasharray', dc.pluck('dashstyle'))
18209
                .attr('stroke', dc.pluck('color'));
18210
        } else {
18211
            itemEnter
18212
                .append('rect')
18213
                .attr('width', _itemHeight)
18214
                .attr('height', _itemHeight)
18215
                .attr('fill', function (d) {return d ? d.color : 'blue';});
18216
        }
18217
18218
        itemEnter.append('text')
18219
                .text(dc.pluck('name'))
18220
                .attr('x', _itemHeight + LABEL_GAP)
18221
                .attr('y', function () {
18222
                    return _itemHeight / 2 + (this.clientHeight ? this.clientHeight : 13) / 2 - 2;
18223
                });
18224
18225
        var _cumulativeLegendTextWidth = 0;
18226
        var row = 0;
18227
        itemEnter.attr('transform', function (d, i) {
18228
            if (_horizontal) {
18229
                var translateBy = 'translate(' + _cumulativeLegendTextWidth + ',' + row * legendItemHeight() + ')';
18230
                var itemWidth   = _autoItemWidth === true ? this.getBBox().width + _gap : _itemWidth;
18231
18232
                if ((_cumulativeLegendTextWidth + itemWidth) >= _legendWidth) {
18233
                    ++row ;
18234
                    _cumulativeLegendTextWidth = 0 ;
18235
                } else {
18236
                    _cumulativeLegendTextWidth += itemWidth;
18237
                }
18238
                return translateBy;
18239
            }
18240
            else {
18241
                return 'translate(0,' + i * legendItemHeight() + ')';
18242
            }
18243
        });
18244
    };
18245
18246
    function legendItemHeight() {
18247
        return _gap + _itemHeight;
18248
    }
18249
18250
    /**
18251
    #### .x([value])
18252
    Set or get x coordinate for legend widget. Default: 0.
18253
    **/
18254
    _legend.x = function (x) {
18255
        if (!arguments.length) {
18256
            return _x;
18257
        }
18258
        _x = x;
18259
        return _legend;
18260
    };
18261
18262
    /**
18263
    #### .y([value])
18264
    Set or get y coordinate for legend widget. Default: 0.
18265
    **/
18266
    _legend.y = function (y) {
18267
        if (!arguments.length) {
18268
            return _y;
18269
        }
18270
        _y = y;
18271
        return _legend;
18272
    };
18273
18274
    /**
18275
    #### .gap([value])
18276
    Set or get gap between legend items. Default: 5.
18277
    **/
18278
    _legend.gap = function (gap) {
18279
        if (!arguments.length) {
18280
            return _gap;
18281
        }
18282
        _gap = gap;
18283
        return _legend;
18284
    };
18285
18286
    /**
18287
    #### .itemHeight([value])
18288
    Set or get legend item height. Default: 12.
18289
    **/
18290
    _legend.itemHeight = function (h) {
18291
        if (!arguments.length) {
18292
            return _itemHeight;
18293
        }
18294
        _itemHeight = h;
18295
        return _legend;
18296
    };
18297
18298
    /**
18299
    #### .horizontal([boolean])
18300
    Position legend horizontally instead of vertically
18301
    **/
18302
    _legend.horizontal = function (_) {
18303
        if (!arguments.length) {
18304
            return _horizontal;
18305
        }
18306
        _horizontal = _;
18307
        return _legend;
18308
    };
18309
18310
    /**
18311
    #### .legendWidth([value])
18312
    Maximum width for horizontal legend. Default: 560.
18313
    **/
18314
    _legend.legendWidth = function (_) {
18315
        if (!arguments.length) {
18316
            return _legendWidth;
18317
        }
18318
        _legendWidth = _;
18319
        return _legend;
18320
    };
18321
18322
    /**
18323
    #### .itemWidth([value])
18324
    legendItem width for horizontal legend. Default: 70.
18325
    **/
18326
    _legend.itemWidth = function (_) {
18327
        if (!arguments.length) {
18328
            return _itemWidth;
18329
        }
18330
        _itemWidth = _;
18331
        return _legend;
18332
    };
18333
18334
    /**
18335
    #### .autoItemWidth([value])
18336
    Turn automatic width for legend items on or off. If true, itemWidth() is ignored.
18337
    This setting takes into account gap(). Default: false.
18338
    **/
18339
    _legend.autoItemWidth = function (_) {
18340
        if (!arguments.length) {
18341
            return _autoItemWidth;
18342
        }
18343
        _autoItemWidth = _;
18344
        return _legend;
18345
    };
18346
18347
    return _legend;
18348
};
18349
18350
/**
18351
## Scatter Plot
18352
Includes: [Coordinate Grid Mixin](#coordinate-grid-mixin)
18353
18354
A scatter plot chart
18355
#### dc.scatterPlot(parent[, chartGroup])
18356
Create a scatter plot instance and attach it to the given parent element.
18357
18358
Parameters:
18359
18360
* parent : string | node | selection | compositeChart - any valid
18361
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
18362
 a dom block element such as a div; or a dom element or d3 selection.
18363
 If the scatter plot is a sub-chart in a [Composite Chart](#composite-chart) then pass in the parent composite
18364
 chart instance.
18365
18366
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
18367
 Interaction with a chart will only trigger events and redraws within the chart's group.
18368
18369
Returns:
18370
A newly created scatter plot instance
18371
18372
```js
18373
// create a scatter plot under #chart-container1 element using the default global chart group
18374
var chart1 = dc.scatterPlot('#chart-container1');
18375
// create a scatter plot under #chart-container2 element using chart group A
18376
var chart2 = dc.scatterPlot('#chart-container2', 'chartGroupA');
18377
// create a sub-chart under a composite parent chart
18378
var chart3 = dc.scatterPlot(compositeChart);
18379
```
18380
18381
 **/
18382
dc.scatterPlot = function (parent, chartGroup) {
18383
    var _chart = dc.coordinateGridMixin({});
18384
    var _symbol = d3.svg.symbol();
18385
18386
    var _existenceAccessor = function (d) { return d.value; };
18387
18388
    var originalKeyAccessor = _chart.keyAccessor();
18389
    _chart.keyAccessor(function (d) { return originalKeyAccessor(d)[0]; });
18390
    _chart.valueAccessor(function (d) { return originalKeyAccessor(d)[1]; });
18391
    _chart.colorAccessor(function () { return _chart._groupName; });
18392
18393
    var _locator = function (d) {
18394
        return 'translate(' + _chart.x()(_chart.keyAccessor()(d)) + ',' +
18395
                              _chart.y()(_chart.valueAccessor()(d)) + ')';
18396
    };
18397
18398
    var _symbolSize = 3;
18399
    var _highlightedSize = 5;
18400
    var _hiddenSize = 0;
18401
18402
    _symbol.size(function (d) {
18403
        if (!_existenceAccessor(d)) {
18404
            return _hiddenSize;
18405
        } else if (this.filtered) {
18406
            return Math.pow(_highlightedSize, 2);
18407
        } else {
18408
            return Math.pow(_symbolSize, 2);
18409
        }
18410
    });
18411
18412
    dc.override(_chart, '_filter', function (filter) {
18413
        if (!arguments.length) {
18414
            return _chart.__filter();
18415
        }
18416
18417
        return _chart.__filter(dc.filters.RangedTwoDimensionalFilter(filter));
18418
    });
18419
18420
    _chart.plotData = function () {
18421
        var symbols = _chart.chartBodyG().selectAll('path.symbol')
18422
            .data(_chart.data());
18423
18424
        symbols
18425
            .enter()
18426
        .append('path')
18427
            .attr('class', 'symbol')
18428
            .attr('opacity', 0)
18429
            .attr('fill', _chart.getColor)
18430
            .attr('transform', _locator);
18431
18432
        dc.transition(symbols, _chart.transitionDuration())
18433
            .attr('opacity', function (d) { return _existenceAccessor(d) ? 1 : 0; })
18434
            .attr('fill', _chart.getColor)
18435
            .attr('transform', _locator)
18436
            .attr('d', _symbol);
18437
18438
        dc.transition(symbols.exit(), _chart.transitionDuration())
18439
            .attr('opacity', 0).remove();
18440
    };
18441
18442
    /**
18443
    #### .existenceAccessor([accessor])
18444
    Get or set the existence accessor.  If a point exists, it is drawn with symbolSize radius and
18445
    opacity 1; if it does not exist, it is drawn with hiddenSize radius and opacity 0. By default,
18446
    the existence accessor checks if the reduced value is truthy.
18447
    **/
18448
18449
    _chart.existenceAccessor = function (acc) {
18450
        if (!arguments.length) {
18451
            return _existenceAccessor;
18452
        }
18453
        _existenceAccessor = acc;
18454
        return this;
18455
    };
18456
18457
    /**
18458
    #### .symbol([type])
18459
    Get or set the symbol type used for each point. By default the symbol is a circle. See the D3
18460
    [docs](https://github.com/mbostock/d3/wiki/SVG-Shapes#wiki-symbol_type) for acceptable types.
18461
    Type can be a constant or an accessor.
18462
18463
    **/
18464
    _chart.symbol = function (type) {
18465
        if (!arguments.length) {
18466
            return _symbol.type();
18467
        }
18468
        _symbol.type(type);
18469
        return _chart;
18470
    };
18471
18472
    /**
18473
    #### .symbolSize([radius])
18474
    Set or get radius for symbols. Default: 3.
18475
18476
    **/
18477
    _chart.symbolSize = function (s) {
18478
        if (!arguments.length) {
18479
            return _symbolSize;
18480
        }
18481
        _symbolSize = s;
18482
        return _chart;
18483
    };
18484
18485
    /**
18486
    #### .highlightedSize([radius])
18487
    Set or get radius for highlighted symbols. Default: 4.
18488
18489
    **/
18490
    _chart.highlightedSize = function (s) {
18491
        if (!arguments.length) {
18492
            return _highlightedSize;
18493
        }
18494
        _highlightedSize = s;
18495
        return _chart;
18496
    };
18497
18498
    /**
18499
    #### .hiddenSize([radius])
18500
    Set or get radius for symbols when the group is empty. Default: 0.
18501
18502
    **/
18503
    _chart.hiddenSize = function (s) {
18504
        if (!arguments.length) {
18505
            return _hiddenSize;
18506
        }
18507
        _hiddenSize = s;
18508
        return _chart;
18509
    };
18510
18511
    _chart.legendables = function () {
18512
        return [{chart: _chart, name: _chart._groupName, color: _chart.getColor()}];
18513
    };
18514
18515
    _chart.legendHighlight = function (d) {
18516
        resizeSymbolsWhere(function (symbol) {
18517
            return symbol.attr('fill') === d.color;
18518
        }, _highlightedSize);
18519
        _chart.selectAll('.chart-body path.symbol').filter(function () {
18520
            return d3.select(this).attr('fill') !== d.color;
18521
        }).classed('fadeout', true);
18522
    };
18523
18524
    _chart.legendReset = function (d) {
18525
        resizeSymbolsWhere(function (symbol) {
18526
            return symbol.attr('fill') === d.color;
18527
        }, _symbolSize);
18528
        _chart.selectAll('.chart-body path.symbol').filter(function () {
18529
            return d3.select(this).attr('fill') !== d.color;
18530
        }).classed('fadeout', false);
18531
    };
18532
18533
    function resizeSymbolsWhere(condition, size) {
18534
        var symbols = _chart.selectAll('.chart-body path.symbol').filter(function () {
18535
            return condition(d3.select(this));
18536
        });
18537
        var oldSize = _symbol.size();
18538
        _symbol.size(Math.pow(size, 2));
18539
        dc.transition(symbols, _chart.transitionDuration()).attr('d', _symbol);
18540
        _symbol.size(oldSize);
18541
    }
18542
18543
    _chart.setHandlePaths = function () {
18544
        // no handle paths for poly-brushes
18545
    };
18546
18547
    _chart.extendBrush = function () {
18548
        var extent = _chart.brush().extent();
18549
        if (_chart.round()) {
18550
            extent[0] = extent[0].map(_chart.round());
18551
            extent[1] = extent[1].map(_chart.round());
18552
18553
            _chart.g().select('.brush')
18554
                .call(_chart.brush().extent(extent));
18555
        }
18556
        return extent;
18557
    };
18558
18559
    _chart.brushIsEmpty = function (extent) {
18560
        return _chart.brush().empty() || !extent || extent[0][0] >= extent[1][0] || extent[0][1] >= extent[1][1];
18561
    };
18562
18563
    function resizeFiltered(filter) {
18564
        var symbols = _chart.selectAll('.chart-body path.symbol').each(function (d) {
18565
            this.filtered = filter && filter.isFiltered(d.key);
18566
        });
18567
18568
        dc.transition(symbols, _chart.transitionDuration()).attr('d', _symbol);
18569
    }
18570
18571
    _chart._brushing = function () {
18572
        var extent = _chart.extendBrush();
18573
18574
        _chart.redrawBrush(_chart.g());
18575
18576
        if (_chart.brushIsEmpty(extent)) {
18577
            dc.events.trigger(function () {
18578
                _chart.filter(null);
18579
                _chart.redrawGroup();
18580
            });
18581
18582
            resizeFiltered(false);
18583
18584
        } else {
18585
            var ranged2DFilter = dc.filters.RangedTwoDimensionalFilter(extent);
18586
            dc.events.trigger(function () {
18587
                _chart.filter(null);
18588
                _chart.filter(ranged2DFilter);
18589
                _chart.redrawGroup();
18590
            }, dc.constants.EVENT_DELAY);
18591
18592
            resizeFiltered(ranged2DFilter);
18593
        }
18594
    };
18595
18596
    _chart.setBrushY = function (gBrush) {
18597
        gBrush.call(_chart.brush().y(_chart.y()));
18598
    };
18599
18600
    return _chart.anchor(parent, chartGroup);
18601
};
18602
18603
/**
18604
## Number Display Widget
18605
Includes: [Base Mixin](#base-mixin)
18606
18607
A display of a single numeric value.
18608
18609
Examples:
18610
18611
* [Test Example](http://dc-js.github.io/dc.js/examples/number.html)
18612
#### dc.numberDisplay(parent[, chartGroup])
18613
Create a Number Display instance and attach it to the given parent element.
18614
18615
Unlike other charts, you do not need to set a dimension. Instead a group object must be provided and
18616
a valueAccessor that returns a single value.
18617
18618
Parameters:
18619
18620
* parent : string | node | selection - any valid
18621
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
18622
 a dom block element such as a div; or a dom element or d3 selection.
18623
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
18624
 The number display widget will only react to filter changes in the chart group.
18625
18626
Returns:
18627
A newly created number display instance
18628
18629
```js
18630
// create a number display under #chart-container1 element using the default global chart group
18631
var display1 = dc.numberDisplay('#chart-container1');
18632
```
18633
18634
**/
18635
dc.numberDisplay = function (parent, chartGroup) {
18636
    var SPAN_CLASS = 'number-display';
18637
    var _formatNumber = d3.format('.2s');
18638
    var _chart = dc.baseMixin({});
18639
    var _html = {one:'', some:'', none:''};
18640
18641
    // dimension not required
18642
    _chart._mandatoryAttributes(['group']);
18643
18644
    /**
18645
    #### .html([object])
18646
     Gets or sets an optional object specifying HTML templates to use depending on the number
18647
     displayed.  The text `%number` will be replaced with the current value.
18648
     - one: HTML template to use if the number is 1
18649
     - zero: HTML template to use if the number is 0
18650
     - some: HTML template to use otherwise
18651
18652
     ```js
18653
     numberWidget.html({
18654
         one:'%number record',
18655
         some:'%number records',
18656
         none:'no records'})
18657
     ```
18658
    **/
18659
18660
    _chart.html = function (s) {
18661
        if (!arguments.length) {
18662
            return _html;
18663
        }
18664
        if (s.none) {
18665
            _html.none = s.none;//if none available
18666
        } else if (s.one) {
18667
            _html.none = s.one;//if none not available use one
18668
        } else if (s.some) {
18669
            _html.none = s.some;//if none and one not available use some
18670
        }
18671
        if (s.one) {
18672
            _html.one = s.one;//if one available
18673
        } else if (s.some) {
18674
            _html.one = s.some;//if one not available use some
18675
        }
18676
        if (s.some) {
18677
            _html.some = s.some;//if some available
18678
        } else if (s.one) {
18679
            _html.some = s.one;//if some not available use one
18680
        }
18681
        return _chart;
18682
    };
18683
18684
    /**
18685
    #### .value()
18686
    Calculate and return the underlying value of the display
18687
    **/
18688
18689
    _chart.value = function () {
18690
        return _chart.data();
18691
    };
18692
18693
    _chart.data(function (group) {
18694
        var valObj = group.value ? group.value() : group.top(1)[0];
18695
        return _chart.valueAccessor()(valObj);
18696
    });
18697
18698
    _chart.transitionDuration(250); // good default
18699
18700
    _chart._doRender = function () {
18701
        var newValue = _chart.value(),
18702
            span = _chart.selectAll('.' + SPAN_CLASS);
18703
18704
        if (span.empty()) {
18705
            span = span.data([0])
18706
                .enter()
18707
                .append('span')
18708
                .attr('class', SPAN_CLASS);
18709
        }
18710
18711
        span.transition()
18712
            .duration(_chart.transitionDuration())
18713
            .ease('quad-out-in')
18714
            .tween('text', function () {
18715
                var interp = d3.interpolateNumber(this.lastValue || 0, newValue);
18716
                this.lastValue = newValue;
18717
                return function (t) {
18718
                    var html = null, num = _chart.formatNumber()(interp(t));
18719
                    if (newValue === 0 && (_html.none !== '')) {
18720
                        html = _html.none;
18721
                    } else if (newValue === 1 && (_html.one !== '')) {
18722
                        html = _html.one;
18723
                    } else if (_html.some !== '') {
18724
                        html = _html.some;
18725
                    }
18726
                    this.innerHTML = html ? html.replace('%number', num) : num;
18727
                };
18728
            });
18729
    };
18730
18731
    _chart._doRedraw = function () {
18732
        return _chart._doRender();
18733
    };
18734
18735
    /**
18736
    #### .formatNumber([formatter])
18737
    Get or set a function to format the value for the display. By default `d3.format('.2s');` is used.
18738
18739
    **/
18740
    _chart.formatNumber = function (_) {
18741
        if (!arguments.length) {
18742
            return _formatNumber;
18743
        }
18744
        _formatNumber = _;
18745
        return _chart;
18746
    };
18747
18748
    return _chart.anchor(parent, chartGroup);
18749
};
18750
18751
/**
18752
 ## Heat Map
18753
18754
 Includes: [Color Mixin](#color-mixin), [Margin Mixin](#margin-mixin), [Base Mixin](#base-mixin)
18755
18756
 A heat map is matrix that represents the values of two dimensions of data using colors.
18757
18758
 #### dc.heatMap(parent[, chartGroup])
18759
 Create a heat map instance and attach it to the given parent element.
18760
18761
 Parameters:
18762
* parent : string | node | selection - any valid
18763
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) specifying
18764
 a dom block element such as a div; or a dom element or d3 selection.
18765
18766
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
18767
 Interaction with a chart will only trigger events and redraws within the chart's group.
18768
18769
 Returns:
18770
 A newly created heat map instance
18771
18772
 ```js
18773
 // create a heat map under #chart-container1 element using the default global chart group
18774
 var heatMap1 = dc.heatMap('#chart-container1');
18775
 // create a heat map under #chart-container2 element using chart group A
18776
 var heatMap2 = dc.heatMap('#chart-container2', 'chartGroupA');
18777
 ```
18778
18779
 **/
18780
dc.heatMap = function (parent, chartGroup) {
18781
18782
    var DEFAULT_BORDER_RADIUS = 6.75;
18783
18784
    var _chartBody;
18785
18786
    var _cols;
18787
    var _rows;
18788
    var _xBorderRadius = DEFAULT_BORDER_RADIUS;
18789
    var _yBorderRadius = DEFAULT_BORDER_RADIUS;
18790
18791
    var _chart = dc.colorMixin(dc.marginMixin(dc.baseMixin({})));
18792
    _chart._mandatoryAttributes(['group']);
18793
    _chart.title(_chart.colorAccessor());
18794
18795
    var _colsLabel = function (d) {
18796
        return d;
18797
    };
18798
    var _rowsLabel = function (d) {
18799
        return d;
18800
    };
18801
18802
   /**
18803
    #### .colsLabel([labelFunction])
18804
    Set or get the column label function. The chart class uses this function to render
18805
    column labels on the X axis. It is passed the column name.
18806
    ```js
18807
    // the default label function just returns the name
18808
    chart.colsLabel(function(d) { return d; });
18809
    ```
18810
    **/
18811
    _chart.colsLabel = function (_) {
18812
        if (!arguments.length) {
18813
            return _colsLabel;
18814
        }
18815
        _colsLabel = _;
18816
        return _chart;
18817
    };
18818
18819
   /**
18820
    #### .rowsLabel([labelFunction])
18821
    Set or get the row label function. The chart class uses this function to render
18822
    row labels on the Y axis. It is passed the row name.
18823
    ```js
18824
    // the default label function just returns the name
18825
    chart.rowsLabel(function(d) { return d; });
18826
    ```
18827
    **/
18828
    _chart.rowsLabel = function (_) {
18829
        if (!arguments.length) {
18830
            return _rowsLabel;
18831
        }
18832
        _rowsLabel = _;
18833
        return _chart;
18834
    };
18835
18836
    var _xAxisOnClick = function (d) { filterAxis(0, d); };
18837
    var _yAxisOnClick = function (d) { filterAxis(1, d); };
18838
    var _boxOnClick = function (d) {
18839
        var filter = d.key;
18840
        dc.events.trigger(function () {
18841
            _chart.filter(filter);
18842
            _chart.redrawGroup();
18843
        });
18844
    };
18845
18846
    function filterAxis(axis, value) {
18847
        var cellsOnAxis = _chart.selectAll('.box-group').filter(function (d) {
18848
            return d.key[axis] === value;
18849
        });
18850
        var unfilteredCellsOnAxis = cellsOnAxis.filter(function (d) {
18851
            return !_chart.hasFilter(d.key);
18852
        });
18853
        dc.events.trigger(function () {
18854
            if (unfilteredCellsOnAxis.empty()) {
18855
                cellsOnAxis.each(function (d) {
18856
                    _chart.filter(d.key);
18857
                });
18858
            } else {
18859
                unfilteredCellsOnAxis.each(function (d) {
18860
                    _chart.filter(d.key);
18861
                });
18862
            }
18863
            _chart.redrawGroup();
18864
        });
18865
    }
18866
18867
    dc.override(_chart, 'filter', function (filter) {
18868
        if (!arguments.length) {
18869
            return _chart._filter();
18870
        }
18871
18872
        return _chart._filter(dc.filters.TwoDimensionalFilter(filter));
18873
    });
18874
18875
    function uniq(d, i, a) {
18876
        return !i || a[i - 1] !== d;
18877
    }
18878
18879
    /**
18880
     #### .rows([values])
18881
     Gets or sets the values used to create the rows of the heatmap, as an array. By default, all
18882
     the values will be fetched from the data using the value accessor, and they will be sorted in
18883
     ascending order.
18884
     **/
18885
18886
    _chart.rows = function (_) {
18887
        if (arguments.length) {
18888
            _rows = _;
18889
            return _chart;
18890
        }
18891
        if (_rows) {
18892
            return _rows;
18893
        }
18894
        var rowValues = _chart.data().map(_chart.valueAccessor());
18895
        rowValues.sort(d3.ascending);
18896
        return d3.scale.ordinal().domain(rowValues.filter(uniq));
18897
    };
18898
18899
    /**
18900
     #### .cols([keys])
18901
     Gets or sets the keys used to create the columns of the heatmap, as an array. By default, all
18902
     the values will be fetched from the data using the key accessor, and they will be sorted in
18903
     ascending order.
18904
     **/
18905
    _chart.cols = function (_) {
18906
        if (arguments.length) {
18907
            _cols = _;
18908
            return _chart;
18909
        }
18910
        if (_cols) {
18911
            return _cols;
18912
        }
18913
        var colValues = _chart.data().map(_chart.keyAccessor());
18914
        colValues.sort(d3.ascending);
18915
        return d3.scale.ordinal().domain(colValues.filter(uniq));
18916
    };
18917
18918
    _chart._doRender = function () {
18919
        _chart.resetSvg();
18920
18921
        _chartBody = _chart.svg()
18922
            .append('g')
18923
            .attr('class', 'heatmap')
18924
            .attr('transform', 'translate(' + _chart.margins().left + ',' + _chart.margins().top + ')');
18925
18926
        return _chart._doRedraw();
18927
    };
18928
18929
    _chart._doRedraw = function () {
18930
        var rows = _chart.rows(),
18931
            cols = _chart.cols(),
18932
            rowCount = rows.domain().length,
18933
            colCount = cols.domain().length,
18934
            boxWidth = Math.floor(_chart.effectiveWidth() / colCount),
18935
            boxHeight = Math.floor(_chart.effectiveHeight() / rowCount);
18936
18937
        cols.rangeRoundBands([0, _chart.effectiveWidth()]);
18938
        rows.rangeRoundBands([_chart.effectiveHeight(), 0]);
18939
18940
        var boxes = _chartBody.selectAll('g.box-group').data(_chart.data(), function (d, i) {
18941
            return _chart.keyAccessor()(d, i) + '\0' + _chart.valueAccessor()(d, i);
18942
        });
18943
        var gEnter = boxes.enter().append('g')
18944
            .attr('class', 'box-group');
18945
18946
        gEnter.append('rect')
18947
            .attr('class', 'heat-box')
18948
            .attr('fill', 'white')
18949
            .on('click', _chart.boxOnClick());
18950
18951
        if (_chart.renderTitle()) {
18952
            gEnter.append('title');
18953
            boxes.selectAll('title').text(_chart.title());
18954
        }
18955
18956
        dc.transition(boxes.selectAll('rect'), _chart.transitionDuration())
18957
            .attr('x', function (d, i) { return cols(_chart.keyAccessor()(d, i)); })
18958
            .attr('y', function (d, i) { return rows(_chart.valueAccessor()(d, i)); })
18959
            .attr('rx', _xBorderRadius)
18960
            .attr('ry', _yBorderRadius)
18961
            .attr('fill', _chart.getColor)
18962
            .attr('width', boxWidth)
18963
            .attr('height', boxHeight);
18964
18965
        boxes.exit().remove();
18966
18967
        var gCols = _chartBody.selectAll('g.cols');
18968
        if (gCols.empty()) {
18969
            gCols = _chartBody.append('g').attr('class', 'cols axis');
18970
        }
18971
        var gColsText = gCols.selectAll('text').data(cols.domain());
18972
        gColsText.enter().append('text')
18973
              .attr('x', function (d) { return cols(d) + boxWidth / 2; })
18974
              .style('text-anchor', 'middle')
18975
              .attr('y', _chart.effectiveHeight())
18976
              .attr('dy', 12)
18977
              .on('click', _chart.xAxisOnClick())
18978
              .text(_chart.colsLabel());
18979
        dc.transition(gColsText, _chart.transitionDuration())
18980
               .text(_chart.colsLabel())
18981
               .attr('x', function (d) { return cols(d) + boxWidth / 2; });
18982
        gColsText.exit().remove();
18983
        var gRows = _chartBody.selectAll('g.rows');
18984
        if (gRows.empty()) {
18985
            gRows = _chartBody.append('g').attr('class', 'rows axis');
18986
        }
18987
        var gRowsText = gRows.selectAll('text').data(rows.domain());
18988
        gRowsText.enter().append('text')
18989
              .attr('dy', 6)
18990
              .style('text-anchor', 'end')
18991
              .attr('x', 0)
18992
              .attr('dx', -2)
18993
              .on('click', _chart.yAxisOnClick())
18994
              .text(_chart.rowsLabel());
18995
        dc.transition(gRowsText, _chart.transitionDuration())
18996
              .text(_chart.rowsLabel())
18997
              .attr('y', function (d) { return rows(d) + boxHeight / 2; });
18998
        gRowsText.exit().remove();
18999
19000
        if (_chart.hasFilter()) {
19001
            _chart.selectAll('g.box-group').each(function (d) {
19002
                if (_chart.isSelectedNode(d)) {
19003
                    _chart.highlightSelected(this);
19004
                } else {
19005
                    _chart.fadeDeselected(this);
19006
                }
19007
            });
19008
        } else {
19009
            _chart.selectAll('g.box-group').each(function () {
19010
                _chart.resetHighlight(this);
19011
            });
19012
        }
19013
        return _chart;
19014
    };
19015
    /**
19016
     #### .boxOnClick([handler])
19017
     Gets or sets the handler that fires when an individual cell is clicked in the heatmap.
19018
     By default, filtering of the cell will be toggled.
19019
     **/
19020
    _chart.boxOnClick = function (f) {
19021
        if (!arguments.length) {
19022
            return _boxOnClick;
19023
        }
19024
        _boxOnClick = f;
19025
        return _chart;
19026
    };
19027
19028
    /**
19029
     #### .xAxisOnClick([handler])
19030
     Gets or sets the handler that fires when a column tick is clicked in the x axis.
19031
     By default, if any cells in the column are unselected, the whole column will be selected,
19032
     otherwise the whole column will be unselected.
19033
     **/
19034
    _chart.xAxisOnClick = function (f) {
19035
        if (!arguments.length) {
19036
            return _xAxisOnClick;
19037
        }
19038
        _xAxisOnClick = f;
19039
        return _chart;
19040
    };
19041
19042
    /**
19043
     #### .yAxisOnClick([handler])
19044
     Gets or sets the handler that fires when a row tick is clicked in the y axis.
19045
     By default, if any cells in the row are unselected, the whole row will be selected,
19046
     otherwise the whole row will be unselected.
19047
     **/
19048
    _chart.yAxisOnClick = function (f) {
19049
        if (!arguments.length) {
19050
            return _yAxisOnClick;
19051
        }
19052
        _yAxisOnClick = f;
19053
        return _chart;
19054
    };
19055
19056
    /**
19057
     #### .xBorderRadius([value])
19058
     Gets or sets the X border radius.  Set to 0 to get full rectangles.  Default: 6.75
19059
     */
19060
    _chart.xBorderRadius = function (d) {
19061
        if (!arguments.length) {
19062
            return _xBorderRadius;
19063
        }
19064
        _xBorderRadius = d;
19065
        return _chart;
19066
    };
19067
19068
    /**
19069
     #### .xBorderRadius([value])
19070
     Gets or sets the Y border radius.  Set to 0 to get full rectangles.  Default: 6.75
19071
     */
19072
    _chart.yBorderRadius = function (d) {
19073
        if (!arguments.length) {
19074
            return _yBorderRadius;
19075
        }
19076
        _yBorderRadius = d;
19077
        return _chart;
19078
    };
19079
19080
    _chart.isSelectedNode = function (d) {
19081
        return _chart.hasFilter(d.key);
19082
    };
19083
19084
    return _chart.anchor(parent, chartGroup);
19085
};
19086
19087
// https://github.com/d3/d3-plugins/blob/master/box/box.js
19088
(function () {
19089
19090
    // Inspired by http://informationandvisualization.de/blog/box-plot
19091
    d3.box = function () {
19092
        var width = 1,
19093
            height = 1,
19094
            duration = 0,
19095
            domain = null,
19096
            value = Number,
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name Number as value. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
19097
            whiskers = boxWhiskers,
19098
            quartiles = boxQuartiles,
19099
            tickFormat = null;
19100
19101
        // For each small multiple…
19102
        function box(g) {
19103
            g.each(function (d, i) {
19104
                d = d.map(value).sort(d3.ascending);
19105
                var g = d3.select(this),
19106
                    n = d.length,
19107
                    min = d[0],
19108
                    max = d[n - 1];
19109
19110
                // Compute quartiles. Must return exactly 3 elements.
19111
                var quartileData = d.quartiles = quartiles(d);
19112
19113
                // Compute whiskers. Must return exactly 2 elements, or null.
19114
                var whiskerIndices = whiskers && whiskers.call(this, d, i),
19115
                    whiskerData = whiskerIndices && whiskerIndices.map(function (i) { return d[i]; });
19116
19117
                // Compute outliers. If no whiskers are specified, all data are 'outliers'.
19118
                // We compute the outliers as indices, so that we can join across transitions!
19119
                var outlierIndices = whiskerIndices ?
19120
                    d3.range(0, whiskerIndices[0]).concat(d3.range(whiskerIndices[1] + 1, n)) : d3.range(n);
19121
19122
                // Compute the new x-scale.
19123
                var x1 = d3.scale.linear()
19124
                    .domain(domain && domain.call(this, d, i) || [min, max])
19125
                    .range([height, 0]);
19126
19127
                // Retrieve the old x-scale, if this is an update.
19128
                var x0 = this.__chart__ || d3.scale.linear()
19129
                    .domain([0, Infinity])
19130
                    .range(x1.range());
19131
19132
                // Stash the new scale.
19133
                this.__chart__ = x1;
19134
19135
                // Note: the box, median, and box tick elements are fixed in number,
19136
                // so we only have to handle enter and update. In contrast, the outliers
19137
                // and other elements are variable, so we need to exit them! Variable
19138
                // elements also fade in and out.
19139
19140
                // Update center line: the vertical line spanning the whiskers.
19141
                var center = g.selectAll('line.center')
19142
                    .data(whiskerData ? [whiskerData] : []);
19143
19144
                center.enter().insert('line', 'rect')
19145
                    .attr('class', 'center')
19146
                    .attr('x1', width / 2)
19147
                    .attr('y1', function (d) { return x0(d[0]); })
19148
                    .attr('x2', width / 2)
19149
                    .attr('y2', function (d) { return x0(d[1]); })
19150
                    .style('opacity', 1e-6)
19151
                  .transition()
19152
                    .duration(duration)
19153
                    .style('opacity', 1)
19154
                    .attr('y1', function (d) { return x1(d[0]); })
19155
                    .attr('y2', function (d) { return x1(d[1]); });
19156
19157
                center.transition()
19158
                    .duration(duration)
19159
                    .style('opacity', 1)
19160
                    .attr('y1', function (d) { return x1(d[0]); })
19161
                    .attr('y2', function (d) { return x1(d[1]); });
19162
19163
                center.exit().transition()
19164
                    .duration(duration)
19165
                    .style('opacity', 1e-6)
19166
                    .attr('y1', function (d) { return x1(d[0]); })
19167
                    .attr('y2', function (d) { return x1(d[1]); })
19168
                    .remove();
19169
19170
                // Update innerquartile box.
19171
                var box = g.selectAll('rect.box')
19172
                    .data([quartileData]);
19173
19174
                box.enter().append('rect')
19175
                    .attr('class', 'box')
19176
                    .attr('x', 0)
19177
                    .attr('y', function (d) { return x0(d[2]); })
19178
                    .attr('width', width)
19179
                    .attr('height', function (d) { return x0(d[0]) - x0(d[2]); })
19180
                  .transition()
19181
                    .duration(duration)
19182
                    .attr('y', function (d) { return x1(d[2]); })
19183
                    .attr('height', function (d) { return x1(d[0]) - x1(d[2]); });
19184
19185
                box.transition()
19186
                    .duration(duration)
19187
                    .attr('y', function (d) { return x1(d[2]); })
19188
                    .attr('height', function (d) { return x1(d[0]) - x1(d[2]); });
19189
19190
                // Update median line.
19191
                var medianLine = g.selectAll('line.median')
19192
                    .data([quartileData[1]]);
19193
19194
                medianLine.enter().append('line')
19195
                    .attr('class', 'median')
19196
                    .attr('x1', 0)
19197
                    .attr('y1', x0)
19198
                    .attr('x2', width)
19199
                    .attr('y2', x0)
19200
                    .transition()
19201
                    .duration(duration)
19202
                    .attr('y1', x1)
19203
                    .attr('y2', x1);
19204
19205
                medianLine.transition()
19206
                    .duration(duration)
19207
                    .attr('y1', x1)
19208
                    .attr('y2', x1);
19209
19210
                // Update whiskers.
19211
                var whisker = g.selectAll('line.whisker')
19212
                    .data(whiskerData || []);
19213
19214
                whisker.enter().insert('line', 'circle, text')
19215
                    .attr('class', 'whisker')
19216
                    .attr('x1', 0)
19217
                    .attr('y1', x0)
19218
                    .attr('x2', width)
19219
                    .attr('y2', x0)
19220
                    .style('opacity', 1e-6)
19221
                  .transition()
19222
                    .duration(duration)
19223
                    .attr('y1', x1)
19224
                    .attr('y2', x1)
19225
                    .style('opacity', 1);
19226
19227
                whisker.transition()
19228
                    .duration(duration)
19229
                    .attr('y1', x1)
19230
                    .attr('y2', x1)
19231
                    .style('opacity', 1);
19232
19233
                whisker.exit().transition()
19234
                    .duration(duration)
19235
                    .attr('y1', x1)
19236
                    .attr('y2', x1)
19237
                    .style('opacity', 1e-6)
19238
                    .remove();
19239
19240
                // Update outliers.
19241
                var outlier = g.selectAll('circle.outlier')
19242
                    .data(outlierIndices, Number);
19243
19244
                outlier.enter().insert('circle', 'text')
19245
                    .attr('class', 'outlier')
19246
                    .attr('r', 5)
19247
                    .attr('cx', width / 2)
19248
                    .attr('cy', function (i) { return x0(d[i]); })
19249
                    .style('opacity', 1e-6)
19250
                    .transition()
19251
                    .duration(duration)
19252
                    .attr('cy', function (i) { return x1(d[i]); })
19253
                    .style('opacity', 1);
19254
19255
                outlier.transition()
19256
                    .duration(duration)
19257
                    .attr('cy', function (i) { return x1(d[i]); })
19258
                    .style('opacity', 1);
19259
19260
                outlier.exit().transition()
19261
                    .duration(duration)
19262
                    .attr('cy', function (i) { return x1(d[i]); })
19263
                    .style('opacity', 1e-6)
19264
                    .remove();
19265
19266
                // Compute the tick format.
19267
                var format = tickFormat || x1.tickFormat(8);
19268
19269
                // Update box ticks.
19270
                var boxTick = g.selectAll('text.box')
19271
                    .data(quartileData);
19272
19273
                boxTick.enter().append('text')
19274
                    .attr('class', 'box')
19275
                    .attr('dy', '.3em')
19276
                    .attr('dx', function (d, i) { return i & 1 ? 6 : -6; })
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
19277
                    .attr('x', function (d, i) { return i & 1 ? width : 0; })
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
19278
                    .attr('y', x0)
19279
                    .attr('text-anchor', function (d, i) { return i & 1 ? 'start' : 'end'; })
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
19280
                    .text(format)
19281
                    .transition()
19282
                    .duration(duration)
19283
                    .attr('y', x1);
19284
19285
                boxTick.transition()
19286
                    .duration(duration)
19287
                    .text(format)
19288
                    .attr('y', x1);
19289
19290
                // Update whisker ticks. These are handled separately from the box
19291
                // ticks because they may or may not exist, and we want don't want
19292
                // to join box ticks pre-transition with whisker ticks post-.
19293
                var whiskerTick = g.selectAll('text.whisker')
19294
                    .data(whiskerData || []);
19295
19296
                whiskerTick.enter().append('text')
19297
                    .attr('class', 'whisker')
19298
                    .attr('dy', '.3em')
19299
                    .attr('dx', 6)
19300
                    .attr('x', width)
19301
                    .attr('y', x0)
19302
                    .text(format)
19303
                    .style('opacity', 1e-6)
19304
                    .transition()
19305
                    .duration(duration)
19306
                    .attr('y', x1)
19307
                    .style('opacity', 1);
19308
19309
                whiskerTick.transition()
19310
                    .duration(duration)
19311
                    .text(format)
19312
                    .attr('y', x1)
19313
                    .style('opacity', 1);
19314
19315
                whiskerTick.exit().transition()
19316
                    .duration(duration)
19317
                    .attr('y', x1)
19318
                    .style('opacity', 1e-6)
19319
                    .remove();
19320
            });
19321
            d3.timer.flush();
19322
        }
19323
19324
        box.width = function (x) {
19325
            if (!arguments.length) {
19326
                return width;
19327
            }
19328
            width = x;
19329
            return box;
19330
        };
19331
19332
        box.height = function (x) {
19333
            if (!arguments.length) {
19334
                return height;
19335
            }
19336
            height = x;
19337
            return box;
19338
        };
19339
19340
        box.tickFormat = function (x) {
19341
            if (!arguments.length) {
19342
                return tickFormat;
19343
            }
19344
            tickFormat = x;
19345
            return box;
19346
        };
19347
19348
        box.duration = function (x) {
19349
            if (!arguments.length) {
19350
                return duration;
19351
            }
19352
            duration = x;
19353
            return box;
19354
        };
19355
19356
        box.domain = function (x) {
19357
            if (!arguments.length) {
19358
                return domain;
19359
            }
19360
            domain = x === null ? x : d3.functor(x);
19361
            return box;
19362
        };
19363
19364
        box.value = function (x) {
19365
            if (!arguments.length) {
19366
                return value;
19367
            }
19368
            value = x;
19369
            return box;
19370
        };
19371
19372
        box.whiskers = function (x) {
19373
            if (!arguments.length) {
19374
                return whiskers;
19375
            }
19376
            whiskers = x;
19377
            return box;
19378
        };
19379
19380
        box.quartiles = function (x) {
19381
            if (!arguments.length) {
19382
                return quartiles;
19383
            }
19384
            quartiles = x;
19385
            return box;
19386
        };
19387
19388
        return box;
19389
    };
19390
19391
    function boxWhiskers(d) {
19392
        return [0, d.length - 1];
19393
    }
19394
19395
    function boxQuartiles(d) {
19396
        return [
19397
            d3.quantile(d, 0.25),
19398
            d3.quantile(d, 0.5),
19399
            d3.quantile(d, 0.75)
19400
        ];
19401
    }
19402
19403
})();
19404
19405
/**
19406
 ## Box Plot
19407
19408
 Includes: [Coordinate Grid Mixin](#coordinate-grid-mixin)
19409
19410
 A box plot is a chart that depicts numerical data via their quartile ranges.
19411
19412
 #### dc.boxPlot(parent[, chartGroup])
19413
 Create a box plot instance and attach it to the given parent element.
19414
19415
 Parameters:
19416
 * parent : string | node | selection - any valid
19417
 [d3 single selector](https://github.com/mbostock/d3/wiki/Selections#selecting-elements) representing
19418
 a dom block element such as a div; or a dom element or d3 selection.
19419
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in.
19420
 Interaction with a chart will only trigger events and redraws within the chart's group.
19421
19422
 Returns:
19423
 A newly created box plot instance
19424
19425
 ```js
19426
 // create a box plot under #chart-container1 element using the default global chart group
19427
 var boxPlot1 = dc.boxPlot('#chart-container1');
19428
 // create a box plot under #chart-container2 element using chart group A
19429
 var boxPlot2 = dc.boxPlot('#chart-container2', 'chartGroupA');
19430
 ```
19431
19432
 **/
19433
dc.boxPlot = function (parent, chartGroup) {
19434
    var _chart = dc.coordinateGridMixin({});
19435
19436
    // Returns a function to compute the interquartile range.
19437
    function DEFAULT_WHISKERS_IQR (k) {
19438
        return function (d) {
19439
            var q1 = d.quartiles[0],
19440
                q3 = d.quartiles[2],
19441
                iqr = (q3 - q1) * k,
19442
                i = -1,
19443
                j = d.length;
19444
            /*jshint -W116*/
19445
            /*jshint -W035*/
19446
            while (d[++i] < q1 - iqr) {}
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
19447
            while (d[--j] > q3 + iqr) {}
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
19448
            /*jshint +W116*/
19449
            return [i, j];
19450
            /*jshint +W035*/
19451
        };
19452
    }
19453
19454
    var _whiskerIqrFactor = 1.5;
19455
    var _whiskersIqr = DEFAULT_WHISKERS_IQR;
19456
    var _whiskers = _whiskersIqr(_whiskerIqrFactor);
19457
19458
    var _box = d3.box();
19459
    var _tickFormat = null;
19460
19461
    var _boxWidth = function (innerChartWidth, xUnits) {
19462
        if (_chart.isOrdinal()) {
19463
            return _chart.x().rangeBand();
19464
        } else {
19465
            return innerChartWidth / (1 + _chart.boxPadding()) / xUnits;
19466
        }
19467
    };
19468
19469
    // default padding to handle min/max whisker text
19470
    _chart.yAxisPadding(12);
19471
19472
    // default to ordinal
19473
    _chart.x(d3.scale.ordinal());
19474
    _chart.xUnits(dc.units.ordinal);
19475
19476
    // valueAccessor should return an array of values that can be coerced into numbers
19477
    // or if data is overloaded for a static array of arrays, it should be `Number`.
19478
    // Empty arrays are not included.
19479
    _chart.data(function (group) {
19480
        return group.all().map(function (d) {
19481
            d.map = function (accessor) { return accessor.call(d, d); };
19482
            return d;
19483
        }).filter(function (d) {
19484
            var values = _chart.valueAccessor()(d);
19485
            return values.length !== 0;
19486
        });
19487
    });
19488
19489
    /**
19490
    #### .boxPadding([padding])
19491
    Get or set the spacing between boxes as a fraction of box size. Valid values are within 0-1.
19492
    See the [d3 docs](https://github.com/mbostock/d3/wiki/Ordinal-Scales#wiki-ordinal_rangeBands)
19493
    for a visual description of how the padding is applied.
19494
19495
    Default: 0.8
19496
    **/
19497
    _chart.boxPadding = _chart._rangeBandPadding;
19498
    _chart.boxPadding(0.8);
19499
19500
    /**
19501
    #### .outerPadding([padding])
19502
    Get or set the outer padding on an ordinal box chart. This setting has no effect on non-ordinal charts
19503
    or on charts with a custom `.boxWidth`. Will pad the width by `padding * barWidth` on each side of the chart.
19504
19505
    Default: 0.5
19506
    **/
19507
    _chart.outerPadding = _chart._outerRangeBandPadding;
19508
    _chart.outerPadding(0.5);
19509
19510
    /**
19511
     #### .boxWidth(width || function(innerChartWidth, xUnits) { ... })
19512
     Get or set the numerical width of the boxplot box. The width may also be a function taking as
19513
     parameters the chart width excluding the right and left margins, as well as the number of x
19514
     units.
19515
     **/
19516
    _chart.boxWidth = function (_) {
19517
        if (!arguments.length) {
19518
            return _boxWidth;
19519
        }
19520
        _boxWidth = d3.functor(_);
19521
        return _chart;
19522
    };
19523
19524
    var boxTransform = function (d, i) {
19525
        var xOffset = _chart.x()(_chart.keyAccessor()(d, i));
19526
        return 'translate(' + xOffset + ', 0)';
19527
    };
19528
19529
    _chart._preprocessData = function () {
19530
        if (_chart.elasticX()) {
19531
            _chart.x().domain([]);
19532
        }
19533
    };
19534
19535
    _chart.plotData = function () {
19536
        var _calculatedBoxWidth = _boxWidth(_chart.effectiveWidth(), _chart.xUnitCount());
19537
19538
        _box.whiskers(_whiskers)
19539
            .width(_calculatedBoxWidth)
19540
            .height(_chart.effectiveHeight())
19541
            .value(_chart.valueAccessor())
19542
            .domain(_chart.y().domain())
19543
            .duration(_chart.transitionDuration())
19544
            .tickFormat(_tickFormat);
19545
19546
        var boxesG = _chart.chartBodyG().selectAll('g.box').data(_chart.data(), function (d) { return d.key; });
19547
19548
        renderBoxes(boxesG);
19549
        updateBoxes(boxesG);
19550
        removeBoxes(boxesG);
19551
19552
        _chart.fadeDeselectedArea();
19553
    };
19554
19555
    function renderBoxes(boxesG) {
19556
        var boxesGEnter = boxesG.enter().append('g');
19557
19558
        boxesGEnter
19559
            .attr('class', 'box')
19560
            .attr('transform', boxTransform)
19561
            .call(_box)
19562
            .on('click', function (d) {
19563
                _chart.filter(d.key);
19564
                _chart.redrawGroup();
19565
            });
19566
    }
19567
19568
    function updateBoxes(boxesG) {
19569
        dc.transition(boxesG, _chart.transitionDuration())
19570
            .attr('transform', boxTransform)
19571
            .call(_box)
19572
            .each(function () {
19573
                d3.select(this).select('rect.box').attr('fill', _chart.getColor);
19574
            });
19575
    }
19576
19577
    function removeBoxes(boxesG) {
19578
        boxesG.exit().remove().call(_box);
19579
    }
19580
19581
    _chart.fadeDeselectedArea = function () {
19582
        if (_chart.hasFilter()) {
19583
            _chart.g().selectAll('g.box').each(function (d) {
19584
                if (_chart.isSelectedNode(d)) {
19585
                    _chart.highlightSelected(this);
19586
                } else {
19587
                    _chart.fadeDeselected(this);
19588
                }
19589
            });
19590
        } else {
19591
            _chart.g().selectAll('g.box').each(function () {
19592
                _chart.resetHighlight(this);
19593
            });
19594
        }
19595
    };
19596
19597
    _chart.isSelectedNode = function (d) {
19598
        return _chart.hasFilter(d.key);
19599
    };
19600
19601
    _chart.yAxisMin = function () {
19602
        var min = d3.min(_chart.data(), function (e) {
19603
            return d3.min(_chart.valueAccessor()(e));
19604
        });
19605
        return dc.utils.subtract(min, _chart.yAxisPadding());
19606
    };
19607
19608
    _chart.yAxisMax = function () {
19609
        var max = d3.max(_chart.data(), function (e) {
19610
            return d3.max(_chart.valueAccessor()(e));
19611
        });
19612
        return dc.utils.add(max, _chart.yAxisPadding());
19613
    };
19614
19615
    /**
19616
     #### .tickFormat()
19617
     Set the numerical format of the boxplot median, whiskers and quartile labels. Defaults to
19618
     integer formatting.
19619
     ```js
19620
     // format ticks to 2 decimal places
19621
     chart.tickFormat(d3.format('.2f'));
19622
     ```
19623
     **/
19624
    _chart.tickFormat = function (x) {
19625
        if (!arguments.length) {
19626
            return _tickFormat;
19627
        }
19628
        _tickFormat = x;
19629
        return _chart;
19630
    };
19631
19632
    return _chart.anchor(parent, chartGroup);
19633
};
19634
19635
// Renamed functions
19636
19637
dc.abstractBubbleChart = dc.bubbleMixin;
19638
dc.baseChart = dc.baseMixin;
19639
dc.capped = dc.capMixin;
19640
dc.colorChart = dc.colorMixin;
19641
dc.coordinateGridChart = dc.coordinateGridMixin;
19642
dc.marginable = dc.marginMixin;
19643
dc.stackableChart = dc.stackMixin;
19644
19645
// Expose d3 and crossfilter, so that clients in browserify
19646
// case can obtain them if they need them.
19647
dc.d3 = d3;
19648
dc.crossfilter = crossfilter;
19649
19650
return dc;}
19651
    if(typeof define === "function" && define.amd) {
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
19652
        define(["d3", "crossfilter"], _dc);
19653
    } else if(typeof module === "object" && module.exports) {
19654
        var _d3 = require('d3');
19655
        var _crossfilter = require('crossfilter');
19656
        // When using npm + browserify, 'crossfilter' is a function,
19657
        // since package.json specifies index.js as main function, and it
19658
        // does special handling. When using bower + browserify,
19659
        // there's no main in bower.json (in fact, there's no bower.json),
19660
        // so we need to fix it.
19661
        if (typeof _crossfilter !== "function") {
19662
            _crossfilter = _crossfilter.crossfilter;
19663
        }
19664
        module.exports = _dc(_d3, _crossfilter);
19665
    } else {
19666
        this.dc = _dc(d3, crossfilter);
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable crossfilter seems to be never declared. If this is a global, consider adding a /** global: crossfilter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
19667
    }
19668
}
19669
)();
19670
19671
//# sourceMappingURL=dc.js.map